2012-09-28 27 views
0

我已經main.xml中和custom.xml安卓:我已經建立佈局/ custom.xml如何知道它的包名

我想這custom.xml會像用戶控制的自定義視圖,所以我已將2個這些標籤放入mail.xml中,如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="#FFFFFF" > 

    <custom 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" /> 

    <custom 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" /> 

</LinearLayout> 

但它不起作用。

回答

1

嘗試使用包含標記。

<include layout="@layout/custom" 
    android:id="@+id/custom1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" /> 
+0

非常感謝!這個對我有用!我會在5分鐘內接受它,這將是可能的 – Sergey

+0

順便說一句,如何通過Java代碼包含此佈局自定義視圖? – Sergey

+0

如果你想在Java中使用它,那麼你可以執行一個'View customView = findViewById(R.id.custom1)'來從你當前的佈局中獲取視圖,或者添加一個你可以使用'LayoutInflater'的新視圖(最有可能來自一個'Activity')並且調用'View customView = getLayoutInflater()。inflate(R.layout.custom,null);'來創建一個新的。然後你用'view.addView(customView);'添加到你想要的任何視圖中。 – MCeley