Android形状背景

是否有可能在xml中绘制一个形状,并使用png作为该形状的背景? 我已经有了这个形状(这是一个圆angular的正方形),我想给这个广场添加一个背景。

是的,你可以使用任何形状文件作为任何视图的背景。 此示例在形状周围创build具有白色和黑色边框的圆形背景。

示例:

rounded_corner.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" > 

//尝试这种方式,这将帮助你

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rounded_corner" android:padding="2dp" android:orientation="vertical" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/yourdrawable /> </LinearLayout>