2012-07-03 8 views
37

xmlでシェイプを描き、シェイプの背景としてpngを使用できますか?私はすでに形をしています(角が丸い正方形です)、その正方形に背景を置いていきたいと思います。Androidシェイプの背景

+1

を助けるこの方法を試してみてください出来る。 –

+1

投票の理由はありませんか? –

+0

私は知っている、なぜ誰かがdownvoted –

答えて

68

はい、いずれのビューの背景としても任意のシェイプファイルを使用できます。このサンプルは、白い色と丸みを帯びた背景を作成します。

サンプル:uはこれを使用することができます

<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> 

rounded_corner.xml、

<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" > 
+2

を投票すると、描画可能なイメージ、つまり画像を配置できますか? –

+0

いいえ、図形xmlにdrawableを追加することはできません。 –

+1

OPは.pngイメージをバックグラウンドにします。 –

1

//これはyaあなたを

<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>