2017-06-03 8 views
0

私はネットの検索でデューデリジェンスをしましたが、以下のための適切な解決策を見つけることができません。Androidボタンのアラインメント

私はテーブルレイアウトとテーブル行を使用しています。私はTEXTで3つのボタンを入れています。ここにレイアウトファイルのサンプルがあります。

<?xml version="1.0" encoding="utf-8"?> 

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tlRemoteTable" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:stretchColumns="*"> 

    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="ABCD" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="ABCDEFGHI" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:text="ABCDEFGHIJKLMNOP" /> 
    </TableRow> 

</TableLayout> 

画像結果はここにある:

Uneven Layout

私の目的は、それも、すべての1/3比を有するメイクです。私は、テキストの長さがそれを拡張するものであることを理解しています。代わりにテキストを折り返すことはできますか?

最終的な結果は、動的に生成されるファイルになります。だから、私はXMLの代わりにそれをプログラミングするでしょう。

答えて

0
<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tlRemoteTable" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:stretchColumns="*"> 

    <TableRow 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1.0f"> 

     <Button 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:text="ABCD" /> 

     <Button 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:text="ABCDEFGHI" /> 

     <Button 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:text="ABCDEFGHIJKLMNOP" /> 
    </TableRow> 

</TableLayout> 

あなたはすべてのセットを0dpするボタンの幅を変更することができます

0

感謝を働いています!それはうまくいった!

これは誰でも必要なプログラムコードです

TableLayout.LayoutParams trParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,TableLayout.LayoutParams.MATCH_PARENT, 1.0f); 
TableRow.LayoutParams btnParams = new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT); 
関連する問題