2011-08-01 17 views
1

ナビゲーションバーのレイアウトに問題があります。私はボタンの中央にあるテキストの下にあるアイコンを持つことを望んでいました。現在、アイコンが描画されると、ページ外にテキストがプッシュされます。それを取り戻すための唯一の方法は、アンドロイドを使用することです:drawablePadding =「」(hereから)負の値を使用したが、それは次のようになります。Android:画像ボタンアイコンとテキスト

<LinearLayout android:id="@+id/navbar" 
    android:layout_alignParentBottom="true" android:gravity="center" 
    android:layout_width="fill_parent" android:background="#001" 
    android:layout_height="60dip" android:layout_weight="1" 
    android:orientation="horizontal"> 

    <Button android:layout_height="fill_parent" android:id="@+id/navhomebtn" android:enabled="false" 
     android:textColor="#FFF" android:background="@drawable/navbuttonselected" android:drawableTop="@drawable/homeicon" 
     android:drawablePadding="-40dip" 
     android:text="Home" android:layout_weight=".25" android:layout_width="0dip" /> 

    <Button android:layout_height="fill_parent" android:id="@+id/navsearchbtn" 
     android:textColor="#FFF" android:background="@drawable/navbuttons" 
     android:text="Search" android:layout_weight=".25" 
     android:layout_width="0dip" /> 

    <Button android:layout_height="fill_parent" android:id="@+id/navfavbtn" 
     android:textColor="#FFF" android:background="@drawable/navbuttons" 
     android:text="Favorites" android:layout_weight=".25" 
     android:layout_width="0dip" /> 
    <Button android:layout_height="fill_parent" android:id="@+id/navlistbtn" 
     android:textColor="#FFF" android:background="@drawable/navbuttons" 
     android:text="Loans" android:layout_weight=".25" 
     android:layout_width="0dip" /> 

</LinearLayout> 

enter image description here

私のXMLは次のようになりますあなたはこのように行うことができ、ボタンのテキストや画像を設定するには

+0

ちょうどすべての余分なパラメータ(layout_weight、パディング、背景を)失うそれまではすべてが正しく表示されます。次に、bacyを段階的に追加し始めます。問題が見つかるでしょう。テキストとバックグラウンドのボタンが画像を正しく中央揃えしていることをテストしただけで、問題は余分なパラメータのどこかに隠れているはずです。 –

答えて

3

あなたのボタンはあなたが同様のTextViewとImageViewのを含むrelativelayoutを使用する場合があります見る方法。次に、relativelayouts clickable属性をtrueに設定し、背景属性をnavbuttons drawableに設定します。

もう一つの方法は、このようなdrawableLeft /右/上/下の属性を使用することです:

<Button 
    android:id="@+id/home_button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/home_icon" 
    android:background="@drawable/nav_background" 
    android:text="Home"/> 
+0

ありがとう、私はそれについて考えていないが、その周りの素敵な作品:) – Nick

2

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <Button 
      android:text="Button" 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:drawableTop="@drawable/icon"></Button> 
    </LinearLayout> 

希望、それはあなたを助けます!

関連する問題