是否可以在 xml 中绘制一个形状,并使用 png 作为该形状的背景?我已经有了形状(它是一个带圆角的正方形),我想为该正方形添加背景。
是的,您可以使用任何形状文件作为任何视图的背景。此示例创建圆形背景,形状周围有白色和黑色边框。
样本 :
圆角.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp" />
<stroke
android:width="0.5dp"
android:color="@color/color_grey" />
<solid android:color="@color/color_white" />
</shape>
你可以用它作为,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal"
android:background="@drawable/rounded_corner"
android:orientation="vertical" >
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)