2011-12-19 8 views
1

同じレイアウトの2つのボタンを直線レイアウトに配置しようとしました。私の問題は、左ボタンが正しいボタンと同じ高さにないことです。linearlayoutのlayout_weightとlayout_width = 0dpが予期しないレイアウトを作成する

私は答えを探しましたが、私の問題に関連するものは見つかりませんでした。ここ

私はアンドロイド2.1デバイス上で何を得るの絵:あなたの助け `

<LinearLayout 
    android:layout_alignParentBottom="true" 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="bottom"> 

    <Button 
     android:id="@+id/take_pic_btn" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="@string/take_pic" /> 

    <Button 
     android:id="@+id/from_gallery_btn" 
     android:text="@string/from_gallery" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     /> 
</LinearLayout>` 

感謝:私はこのコードを使用し http://tinypic.com/r/eskb4n/5

編集:私は、私は2つの可能な解決策を参照。.. layout_widthの代わりに、fill_parentため

+0

正確に何をしたいですか? –

+0

同じサイズで、利用可能なすべてのスペースを使用する、隣り合う2つのボタンを作成しようとしました –

+0

LadaRaiderで答えが問題を解決しませんでした。しかし、ありがとう!この問題を解決した –

答えて

0

あなたは、Android設定することができます。両方のボタンをlayout_height = "fill_parentを"。

希望すると便利です。

+0

!どうもありがとう! –

+0

問題ありません!あなたを助けてくれてうれしい! –

0

を0dpを使用:

1)を設定した固定のandroid:layout_heightので、両方のボタンが確実に等しい垂直方向のスペースがかかります。

<LinearLayout 
android:layout_alignParentBottom="true" 
android:id="@+id/linearLayout1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:gravity="bottom"> 

<Button 
    android:id="@+id/take_pic_btn" 
    android:layout_width="fill_parent" 
    android:layout_height="40dip" 
    android:layout_weight="1" 
    android:text="@string/take_pic" /> 

<Button 
    android:id="@+id/from_gallery_btn" 
    android:text="@string/from_gallery" 
    android:layout_width="fill_parent" 
    android:layout_height="40dip" 
    android:layout_weight="1" 
    /> 

2)のみの単一ラインを取るために、ボタンの上にテキストを強制します。

<LinearLayout 
android:layout_alignParentBottom="true" 
android:id="@+id/linearLayout1" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:gravity="bottom"> 

<Button 
    android:id="@+id/take_pic_btn" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:singleLine="true" 
    android:maxLines="1" 
    android:text="@string/take_pic" /> 

<Button 
    android:id="@+id/from_gallery_btn" 
    android:text="@string/from_gallery" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:singleLine="true" 
    android:maxLines="1" 
    /> 

関連する問題