2012-01-03 87 views
2

我正在開發某種具有2x3自定義按鈕網格的播放器...按鈕在customplayerbutton.xml中製作,然後它們在main.xml中用作「includes」是佈局的問題 - 我的自定義按鈕不適合的TableRow:2x3自定義按鈕網格佈局不適合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> 

回答

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> 
0

我測試您發佈的XML佈局,我沒有得到的輸出,你在這裏顯示,但我有不同。然後我從main.xml文件中刪除了2條語句,現在輸出結果很好。

試試這個。

在1月1日<TableRow>刪除<include>android:layout_gravity="left" 和第二<include>刪除行android:layout_gravity="right"

+0

刪除layout_gravity標籤也無濟於事。如果屏幕尺寸比需要的大,它們會產生影響,並且在這種情況下,前兩個按鈕會被重疊到佈局的左側和右側邊緣。爲了在屏幕上獲得輸出,你應該有一個低英寸(3.2英寸好)的顯示器。它的行爲,如包含android:layout_width不是「fill_parent」,而是「wrap_content」。 – Prizoff 2012-01-04 09:48:26