2014-02-19 40 views

回答

1

,你可以通過在FrameLayout

例如包裝的小部件都做到這一點:

<FrameLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" > 
    <ImageButton 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/image" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/text" 
     android:layout_gravity="center" /> 
</FrameLayout> 
0

您是否過於複雜佈局。只需將文本添加到按鈕。

myImageButton.setText("text"); 

如果你確實想層中的這些觀點,你應該使用的RelativeLayout:

<RealtiveLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageButton 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/img"/>   
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/app_name" 
     android:layout_centerInParent="true"/> 
</RelativeLayout> 

作出特殊情況說明屬性layout_centerInParent的。這是TextView如何正確居中。

0

使用常規的Button,無論如何擴展TextView。然後將背景設置爲圖像並使用setText()設置文本。您甚至可以使用drawableLeft,drawableTop等屬性在文本右上方,下方和/或左側添加圖標&。

相關問題