2012-01-03 9 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:最後に、私のLinearLayoutにTableLayoutを交換することによって、これを解決

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

。ここで私に働いていた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つのステートメントを削除しました。出力は良好です。

これを試してください。第一<TableRow>第一<include>

layout_gravityタグを削除行android:layout_gravity="right"

+0

を削除ラインandroid:layout_gravity="left" と第二<include>を削除するには助けにはなりません。画面サイズが必要以上に大きい場合に影響を与えます。その場合、最初の2つのボタンがレイアウトの左右の端に重力を与えます。スクリーンショットの出力を得るには、低インチ(3.2インチ)のディスプレイが必要です。これは、アンドロイド:layout_widthが "fill_parent"ではなく "wrap_content"を含むように動作します。 – Prizoff

関連する問題