我正在使用2x3网格自定义按钮开发某种播放器...按钮是在customplayerbutton.xml中制作的,然后它们在main.xml中用作“includes”布局有问题 - 我的自定义按钮执行不适合TableRow:
bad layout 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>
答案 0 :(得分:1)
最后,我通过将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>
答案 1 :(得分:0)
我测试了你发布的XML布局,我没有得到你在这里显示的输出,但我有所不同。然后我从main.xml
文件中删除了2个语句,现在输出很好。
试试这个。
在第一个<TableRow>
第一个<include>
中删除第android:layout_gravity="left"
行
和第二个<include>
删除第android:layout_gravity="right"
行