2
我想爲我的android應用程序創建一個自定義TableRow。我從LinearLayout開始,這正是我想要顯示的,但作爲TableLayout中的TableRow。TableRow中的LinearLayout發出警告
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:weightSum="1" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:text="@string/Context" />
<TextView
android:id="@+id/ContextTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:weightSum="1" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.7"
android:text="@string/SHUId" />
<TextView
android:id="@+id/SHUIdTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.3" />
</LinearLayout>
...Others LinearLayouts with 2 TextViews...
</LinearLayout>
所以首先我試圖把這個代碼的TableRow的元素:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
...LinearLayout code from above...
<TableRow />
此時在Eclipse編輯器中正確顯示的佈局,但現在我有主的LinearLayout棉絨警告:「這的LinearLayout佈局或其母公司的TableRow是 無用」
然後我說OK的TableRow是的LinearLayout的子類,那麼我可以簡單地卸下主的LinearLayout,直接把他的性質上的TableRow就這樣:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp" >
<LinearLayout >
<TextView />
<TextView />
<LinearLayout />
<LinearLayout >
<TextView />
<TextView />
<LinearLayout />
...etc...
<TableRow />
但現在佈局不再正確顯示(但沒有警告)。我只看到第一行(帶有2個第一個TextView)。 我錯過了什麼?
我編程添加TableLow在TableLayout中,但在我的XML文件中,它只是一個TableRow – Alexis 2012-08-03 06:27:40
然後,如果它是水平的LinearLayout,是不是可以考慮屬性android:orientation =「vertical」? – Alexis 2012-08-03 06:30:09
好吧,你有你的答案,TableRow是一個水平的LinearLayout,你的最外面的LinearLayout是一個垂直的 - 當你移除它時,你看不到你的第二行,因爲它在水平TableRow的右邊很遠。留下最外面的LinearLayout,並不要發出警告。 – 2012-08-03 06:30:26