【发布时间】:2016-06-27 14:15:55
【问题描述】:
我是 Android 开发新手。我用一个简单的按钮创建了一个简单的项目。我想将图像设置为背景(见图)。我使用了 android:src="@drawable/id_image" 和 android:background="@drawable/id_image2" 但图像没有出现在按钮的整个表面上。任何帮助将不胜感激
【问题讨论】:
标签: android button background
我是 Android 开发新手。我用一个简单的按钮创建了一个简单的项目。我想将图像设置为背景(见图)。我使用了 android:src="@drawable/id_image" 和 android:background="@drawable/id_image2" 但图像没有出现在按钮的整个表面上。任何帮助将不胜感激
【问题讨论】:
标签: android button background
Android,您可以使用android.widget.ImageButton 显示一个普通的“按钮”,并带有自定义的背景图像。
<ImageButton
android:id="@+id/top_bar_btn_right_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:src="@drawable/ic_filter" />
【讨论】:
您可以使用android:src 和android:background 来添加两个图像。
【讨论】:
android:src="@drawable还是android:src="@drawable/id_of_your_image?
当您添加按钮时,您只需转到属性菜单并选择背景/可绘制并选择您的图像
【讨论】:
你可以试试这样的
<RelativeLayout
android:layout_width="250dp"
android:layout_height="400dp"
android:background="your_background_goes_here"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:centerInParent="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="your_icon_above_background"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text_for_your_image"/>
</RelativeLayout>
【讨论】: