2012-07-03 5 views
37

xml 형식을 그릴 수 있습니까? 그 모양의 배경으로 png를 사용할 수 있습니까? 나는 이미 둥근 모서리가있는 사각형을 가지고 있으며 그 사각형에 배경을두고 싶습니다.안드로이드 모양 배경

+1

도움이 될 것입니다이 방법을 시도 할 수있어. –

+1

투표를 거칠 이유가 없습니까? –

+0

나는 누군가가 왜 –

답변

68

예 모든보기의 배경으로 모든 모양 파일을 사용할 수 있습니다. 이 샘플은 둥근 ​​배경을 백색 색상으로하고 검은 색 테두리를 모양 주위에 만듭니다.

샘플 : 유로 사용할 수 있습니다

<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

을 투표하면 drawable 즉 이미지를 넣을 수 있습니까? –

+0

아니요 당신은 shape xml에 drawable을 추가 할 수 없습니다. –

+1

OP는 .png 이미지를 배경으로 유지하려고합니다. –

1

//이 나중에 당신을

<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> 
관련 문제