2011-10-13 8 views
2

ここが問題です。Android TableLayoutはセルの内容を伸ばします

いくつかのImageButtonを含むTableLayoutを作成しています。

各行には3つのImageButtonがありますが、幅はテーブルの幅と同じではありません。 同じことが身長にも当てはまります。

私がやりたいことのすべては、細胞内のImageButtonsは、彼らがしているセンターです。

auto:StretchColumns="*" 

でも私はXMLファイルでそのサイズを指定して、ImageButtons(セルデータ)を伸ばします。

また、同じ行を実行するオプションはありますか?

セルの余白を自動的に計算するようなものです。

答えて

2

ImageButtonにandroid:layout_gravity="center"を設定しようとしましたか?

また、あなたはこのようなLinearLayoutで各ImageButtonをラップすることができます。表レイアウトの

<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <ImageButton android:layout_gravity="center" ...other attributes... /> 
</LinearLayout> 
+0

はい、私は効果を試しませんでした。私は別のアプローチを試みていますが、アプリケーションが不必要に重くなることはありますが(それほど多くはありませんが) – ikromm

+0

レイアウトファイルまたはそのサンプルを投稿してみることができますか? – kaspermoerch

+0

必要はありません。それは少し重い場合でも正しく動作しています。歓声:) – ikromm

1

子どもたちは唯一のTableRowである必要はありません。テーブルレイアウトは、LinearLayout、TextView、ImageButtonなどのすべてのタイプの子をサポートします。

画像ボタンをTableRowにラップしないでください。行として挿入します。ボタンが均等に行を分割するために、同じ量の次の二つの画像ボタンを追加android:orientation="horizontal"

</TableRow> 

<LinearLayout 
    android:id="@+id/LL1" 
    android:layout_width="fill_parent" <---! The Parent is the TableLayout !---> 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

     <ImageButton 
      android:id="@+id/IB1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/coolBGImage1" 
      android:weight="1" /> 

とのLinearLayoutを使用する一列に3 ImageButtonsを置く

<TableRow> 
    <TextView 
     android:id="@+id/tv1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Example Table Row" /> 
</TableRow> 

<ImageButton 
    android:id="@+id/ib1" 
    android:layout_width="fill_parent" <---! The Parent Is The Table Layout !---> 
    android:layout_height="wrap_content" 
    android:background="@drawable/coolBGImage" /> 

<TableRow> 
BLAH BLAH BLAH 
</TableRow> 

</LinearLayout> 
関連する問題