我正在开发某种播放器与2x3网格的自定义按钮…按钮是在customplayerbutton.xml中制作的,然后它们被用作main.xml中的"包括"。布局有一个问题-我的自定义按钮不适合tablelow:
布局不良http://img841.imageshack.us/img841/6492/badlayout.png
我做错了什么?
customplayerbutton.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:drawable/btn_default"
android:clickable="true"
android:focusable="true"
android:longClickable="true"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2.0"
android:gravity="center"
android:text="Track67890"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2.0"
android:gravity="center"
android:text="99:99:999 / 99:99:999"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1" />
</LinearLayout>
main。xml:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:longClickable="true"
android:stretchColumns="*" >
<TableRow
android:id="@+id/TableRow01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<include
android:id="@+id/include01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left"
layout="@layout/customplayerbutton" />
<include
android:id="@+id/include1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
layout="@layout/customplayerbutton" />
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<include
android:id="@+id/include02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
layout="@layout/customplayerbutton" />
<include
android:id="@+id/include04"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
layout="@layout/customplayerbutton" />
</TableRow>
<TableRow
android:id="@+id/TableRow02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<include
android:id="@+id/include03"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
layout="@layout/customplayerbutton" />
<include
android:id="@+id/include05"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
layout="@layout/customplayerbutton" />
</TableRow>
</TableLayout>
最后,我通过将TableLayout替换为LinearLayout来解决这个问题。这是我工作的xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<include
android:id="@+id/include01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
layout="@layout/customplayerbutton" />
<include
android:id="@+id/include00"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
layout="@layout/customplayerbutton" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<include
android:id="@+id/include02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
layout="@layout/customplayerbutton" />
<include
android:id="@+id/include04"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
layout="@layout/customplayerbutton" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" >
<include
android:id="@+id/include03"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
layout="@layout/customplayerbutton" />
<include
android:id="@+id/include05"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"
layout="@layout/customplayerbutton" />
</LinearLayout>
</LinearLayout>
我测试了你发布的XML布局,我没有得到你在这里显示的输出,但我得到了不同的结果。然后我从main.xml
文件中删除了2条语句,现在输出很好。
试试这个。
在第1个<TableRow>
第1个<include>
中去掉一行android:layout_gravity="left"
和第二个<include>
删除行android:layout_gravity="right"