2011-06-22 10 views
5

現在、ButtonBarは5つのボタンで設計されています(これらはすべてImageButtonsですが、現在は3つしかありません)。これは私の最初のアンドロイドプロジェクトなので、私は一緒に勉強しています。私はそれらを拡大縮小することなく均等に各ボタンを重み付けしようとしています(同じ幅ではなく等しいパディングがあります)。これは、これまでの私のコードです:等しいパディングを持つ線形レイアウトの子供たち

<LinearLayout 
android:id="@+id/back" 
android:orientation="horizontal" 
android:layout_height="50dip" 
android:layout_width="fill_parent" 
android:layout_alignParentBottom="true" 
android:background="#000000" 
style="@android:style/ButtonBar" 
android:weightSum="5" 
> 

    <ImageButton 
    android:id="@+id/info_button" 
    android:padding="20dp" 
    android:background="@drawable/info" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    /> 
    <Button 
    android:id="@+id/wishlist_button" 
    android:text="@string/wish_label" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    android:padding="20dp" 
    android:textSize="15dip" 
    android:textColor="#b7b7b7"></Button> 
    <Button 
    android:id="@+id/buy_button" 
    android:text="@string/buy_label" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    android:padding="20dp" 
    android:textSize="15dip" 
    android:textColor="#b7b7b7"/> 
    <ImageButton 
    android:id="@+id/dislike_button" 
    android:padding="20dp" 
    android:background="@drawable/dislike_button" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    /> 
    <ImageButton 
    android:id="@+id/like_button" 
    android:padding="20dp" 
    android:background="@drawable/like_button" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_weight="1" 
    /> 

これは、それが今のように見えるものです: は、重み付けを伸ばし:http://i.imgur.com/MAfjp.png

これは、私はそれが(密接に)見えるようにしたいものです。 非 - 均等に詰め物:http://i.imgur.com/vXTEy.png

ありがとうございます。私はしばらくの間答えを探していて、あまりにも多くを試しました。

答えて

6

ここにある:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/back" 
    android:orientation="horizontal" 
    android:layout_height="50dip" 
    android:layout_width="fill_parent" 
    android:layout_alignParentBottom="true" 
    android:background="#000000" 
    style="@android:style/ButtonBar" 
    android:gravity="center" 
    > 
    <ImageButton 
    android:id="@+id/info_button" 
    android:background="@null" 
    android:src="@drawable/info" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    /> 
    <Button 
    android:id="@+id/wishlist_button" 
    android:text="@string/wish_label" 
    android:background="@null" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    android:textSize="15dip" 
    android:textColor="#b7b7b7"></Button> 
    <Button 
    android:id="@+id/buy_button" 
    android:text="@string/buy_label" 
    android:background="@null" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    android:textSize="15dip" 
    android:textColor="#b7b7b7"/> 
    <ImageButton 
    android:id="@+id/dislike_button" 
    android:background="@null" 
    android:src="@drawable/dislike_button" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    /> 
    <ImageButton 
    android:id="@+id/like_button" 
    android:background="@null" 
    android:src="@drawable/like_button" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    /> 
</LinearLayout> 

私はスタイル= "@アンドロイド:スタイル/ ButtonBarには" 方法がわからない設定されているので、それが正しく表示されない場合削除してください。

+0

恐ろしい!どういうわけか、それはうまくいった!どうもありがとうございました。 – jbenowitz

1

各画像/ボタンの間にスペーサー要素を追加し、画像/ボタンではなくスペーサー要素にlayout_weightを割り当てることができます。だから、このようなものになります。それはあなたのレイアウトに複数のビューが追加されますので、

<LinearLayout 
android:id="@+id/back" 
android:orientation="horizontal" 
android:layout_height="50dip" 
android:layout_width="fill_parent" 
android:layout_alignParentBottom="true" 
android:background="#000000" 
style="@android:style/ButtonBar" 
> 

    <ImageButton 
    android:id="@+id/info_button" 
    android:padding="20dp" 
    android:background="@drawable/info" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    /> 
     <LinearLayout 
     android:layout_height="wrap_content"    
     android:layout_weight="1" /> 
    /> 
    <Button 
    android:id="@+id/wishlist_button" 
    android:text="@string/wish_label" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:padding="20dp" 
    android:textSize="15dip" 
    android:textColor="#b7b7b7"></Button> 
     <LinearLayout 
     android:layout_height="wrap_content"    
     android:layout_weight="1" /> 
    <Button 
    android:id="@+id/buy_button" 
    android:text="@string/buy_label" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:padding="20dp" 
    android:textSize="15dip" 
    android:textColor="#b7b7b7"/> 
     <LinearLayout 
     android:layout_height="wrap_content"    
     android:layout_weight="1" /> 
    <ImageButton 
    android:id="@+id/dislike_button" 
    android:padding="20dp" 
    android:background="@drawable/dislike_button" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    /> 
     <LinearLayout 
     android:layout_height="wrap_content"    
     android:layout_weight="1" /> 
    <ImageButton 
    android:id="@+id/like_button" 
    android:padding="20dp" 
    android:background="@drawable/like_button" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    /> 
</LinearLayout> 

はこれが最もエレガントな解決策ではないかもしれないが、それは、過去に私のために働いています。

+1

不良解決策IMO – BrainCrash

0

LinearLayout内に等しいサイズの同じサイズの画像を持つ画像ボタンのみを使用することを検討してください。

よろしく、 ステファン

関連する問題