可能重複:
How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextViewAndroid的Eclipse如何添加圖像按鈕與文字
我現在只是剛剛在其文本的按鈕,但現在我想添加一個背景圖像。但我不想讓背景圖片覆蓋整個按鈕。我希望它看起來像這張圖片中的按鈕。 (看看應用截圖下的圖片,這是第一張圖片。)這是一張圖片的鏈接。
可能重複:
How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextViewAndroid的Eclipse如何添加圖像按鈕與文字
我現在只是剛剛在其文本的按鈕,但現在我想添加一個背景圖像。但我不想讓背景圖片覆蓋整個按鈕。我希望它看起來像這張圖片中的按鈕。 (看看應用截圖下的圖片,這是第一張圖片。)這是一張圖片的鏈接。
你的意思是與文本的按鈕右側的列表視圖?您可以使用兩個視圖,文本視圖和圖像視圖
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView ...>
<TextView ...>
</LinearLayout>
你可以做這樣的事情:
<Button
android:id="@+id/button_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/[your_image]"
android:text="Your_Text"
android:textSize="48dp" //<==give a dimension to a text
android:textStyle="bold"//<==is better your text is bold
/>
如果妳使用Eclipse,使用圖形編輯器來創建你有多少個按鈕就是了,只是複製並粘貼到您的Xml文件中。並使用Strings.xml來存儲您的文本。
您可以使用android:drawableLeft屬性將圖標設置在左側。 Button是從TextView派生的,所以它支持這個屬性,
好的。謝謝,但是他們的任何其他方式。因爲我有至少200個按鈕,並且這將會是很多文本 – user2005921
創建一個由此佈局組成的新的View子類。然後你可以直接聲明它的名字。儘管如果你有200個,你可能會把它扔進一個ListView?在這種情況下,您將在適配器的GetView函數中用代碼誇大它,而不是將其中的200個放入xml中。 –