0

ImageButtonのテキストのサイズに応じて、このボタンの幅を広くしたいと思います。しかし、失敗した場合。これがXMLからの私のコードであり、テキストが長すぎるときにシミュレーターで実際に表示されるものです。セレクター.9patchの画像、テキストが画像ボタンよりも大きい場合、画像ボタンを広くするにはどうすればよいですか?ありがとう。

            <ImageButton
                android:id="@+id/bonjour"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:scaleType="fitXY"
                android:background="@layout/main_menu_account_white_button_selector"/>

            <TextView
                android:id="@+id/bonjour_text_up"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerHorizontal="false"
                android:text=""
                android:textColor="@color/menubutton_black"
                android:textSize="@dimen/small_bottom_menubutton_title_text_size_dn"
                android:textStyle="bold|italic" />

            <TextView
                android:id="@+id/bonjour_text_dn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/bonjour_text_up"
                android:layout_centerHorizontal="false"
                android:text="ScreenName"
                android:textColor="@color/menubutton_black"
                android:textSize="@dimen/small_bottom_menubutton_title_text_size_dn"
                android:textStyle="bold|italic" />
        </RelativeLayout>


<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true"
           android:drawable="@drawable/main_menu_account_white_button_1" /> <!-- pressed -->
     <item android:state_selected="true"
           android:drawable="@drawable/main_menu_account_white_button_1" /> <!-- pressed -->
     <item android:state_focused="true"
           android:drawable="@drawable/main_menu_account_white_button_0" /> <!-- focused -->
     <item android:drawable="@drawable/main_menu_account_white_button_0" /> <!-- default -->
 </selector>

ここに画像の説明を入力してください

4

2 に答える 2

0

9patch画像をフォルダーに保持drawableし、レイアウトで ImageButton のソース/背景にします。

于 2013-02-12T10:54:48.040 に答える
0

私の問題を解決するのに役立つ回避策は次のとおりです。9patch イメージを RelativeLayout の背景に設定し、ImageButton を削除しました。実際のボタンは次のように行う必要があります: 上部と左側 = 中央の領域でのみスケーラブルとしてマークする必要があります。左側と下部 = コンテンツ全体の長さをマークする必要があります。

            <RelativeLayout
            android:id="@+id/bonjour"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/main_menu_account_white_button_0"
            android:clickable="true" >

            <TextView
                android:id="@+id/bonjour_text_up"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_centerHorizontal="false"
                android:text=""
                android:textColor="@color/menubutton_black"
                android:textSize="@dimen/small_bottom_menubutton_title_text_size_dn"
                android:textStyle="bold|italic" />

            <TextView
                android:id="@+id/bonjour_text_dn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/bonjour_text_up"
                android:layout_centerHorizontal="false"
                android:text="ScreenName"
                android:textColor="@color/menubutton_black"
                android:textSize="@dimen/small_bottom_menubutton_title_text_size_dn"
                android:textStyle="bold|italic" />
        </RelativeLayout>
于 2013-02-12T14:33:47.523 に答える