2013-02-14 59 views
2

我想給形狀LinearLayout'sbackgroundimage。我正在使用下面的XML。 但它只顯示曲線時不顯示圖像。如何賦予LinearLayout的背景圖像形狀?

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <corners android:radius="7dp" /> 
    <stroke android:width="1dp"/> 
    <item> 
     <bitmap android:src="@drawable/locationlable" /> 
    </item> 
</shape> 
+0

你想圓位圖的角落? – 2013-02-14 13:45:28

+1

但我設置圖像的線性佈局背景,所以我怎麼可以讓linearlayout背景圖像形狀 – 2013-02-14 13:46:26

+0

最簡單的方法是編輯位圖給它圓角。如果這不是一種選擇,請查看Romain Guy關於圍繞圖像角落的文章:http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/ – 2013-02-14 13:49:34

回答

1

試試這個

在佈局

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="#FFF"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="5dip" 
     android:background="@drawable/background" 
     android:orientation="vertical" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@xml/shape_round_rect" 
     android:orientation="vertical" /> 

</FrameLayout> 

在XML &的形狀

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle" > 

    <corners android:radius="15dip" /> 

    <stroke 
     android:width="5dip" 
     android:color="#FFF" /> 

</shape> 
0

,如果你想畫圓形,然後你可以使用不同的形狀:

android:shape="ring" 

,如果你想畫一個矩形,然後使用下面的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 

<solid android:color="#ffffff" /> 

<stroke 
    android:width="2dp" 
    android:color="#000000" /> 


</shape> 

爲更多信息請訪問此鏈接http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

+0

但我在linearlayout中有一個背景圖像,所以我如何使用形狀與圖像 – 2013-02-14 13:45:33

2

你可以使用一個layer-list drawable

這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list 
    xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item 
     android:drawable="@[package:]drawable/drawable_resource" 
     android:id="@[+][package:]id/resource_name" 
     android:top="dimension" 
     android:right="dimension" 
     android:bottom="dimension" 
     android:left="dimension" /> 
</layer-list>