2011-12-19 38 views
0

私のアプリのレイアウトは480dpi、480/4は120です。アプリの上部に4つのボタンがあり、120dpiの幅に設定すると、なぜボタンが半分かかりますスクリーン?!一番上に均等にサイズを設定するにはどうすればよいですか?アクティビティの要素の幅が正しくありませんか?

ここ

、私はちょうど上部にある4つのボタンを追加した:

そして最初の二つのボタンは、DPI 120の幅である:

あなたがレイアウトのFILL_PARENTパラメータを使用することができ

+0

を試してみてください。..とても速く答えるため – user370305

答えて

2

これをチェックしてください:

<LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
     <Button 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
     </Button> 
    </LinearLayout> 
+0

Hmm。それは何もしなかった。私はまだあなたのコードを投稿 – Cole

+0

ボタンを見ることができません。 – josephus

+0

それはうまくいった。他のLinearLayoutの中にLinearLayoutを追加しなければなりませんでした。助けてくれてありがとう! – Cole

1

あなたのボタンのそれぞれにウェイト1を追加して希望の効果を得てください

+0

感謝をあなたのレイアウトxmlファイルのコードを投稿してください。したがって、各ボタンの幅は「FILL_PARENT」で、アクティビティのLinearLayoutはまだ「match_parent」ですか?ボタンに「ウェイト1を加える」とはどういう意味ですか?私がそれをすると、layout_width属性を指定する必要があり、ボタンが見えないと言います。 – Cole

0

この

<TableRow android:layout_width="fill_parent" 
    android:weightSum="100" android:layout_height="wrap_content"> 
    <Button android:text="Button" android:layout_weight="25" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    <Button android:text="Button" android:layout_width="wrap_content" 
     android:layout_weight="25" android:layout_height="wrap_content"></Button> 
    <Button android:text="Button" android:layout_weight="25" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
    <Button android:text="Button" android:layout_weight="25" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"></Button> 
</TableRow> 
関連する問題