2014-09-10 100 views
2

我有這樣的LinearLayout:與圓角XML形狀面膜佈局

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <ImageView 
     android:layout_width="100dp" 
     android:layout_height="70dp" 
     android:src="@drawable/ic_launcher" 
     android:scaleType="centerCrop"/> 

    <TextView 
     android:layout_width="100dp" 
     android:layout_height="30dp" 
     android:background="#FFD800" 
     android:textColor="@android:color/black" 
     android:gravity="center" 
     android:text="Text View"/> 
</LinearLayout> 

enter image description here

而且我想用圓角來掩蓋它,就像這樣:

enter image description here

我試圖把它放在一個FrameLayout中,並在其上面放置shape.xml,

但我得到的最多的是:

enter image description here

enter image description here

我正在尋找一種方式來使用shape.xml背景,

但隨着透明內邊界和外面的白色。

我shape.xml:

<shape 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 
<solid 
    android:color="#FFFFFF"> 
</solid> 

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

<padding 
    android:left="5dp" 
    android:top="5dp" 
    android:right="5dp" 
    android:bottom="5dp"> 
</padding> 

<corners 
    android:radius="50dp"> 
</corners> 
</shape> 
+0

你想用圓角xml掩飾整個佈局嗎?請發佈您的整個XML佈局文件代碼。 – GrIsHu 2014-09-10 11:11:55

+0

@GrlsHu是的,我想用角落xml掩蓋整個佈局。 (添加我的佈局) – David 2014-09-10 12:04:09

+0

看看我的答案。 @David – GrIsHu 2014-09-10 12:19:56

回答

3

創建一個九宮白色圓角外,中間透明,(「逆九宮」),並把它放在頂部您的LinearLayout嘗試了。這是一種常見的做法。

+0

不知道這是否是最好的答案,但它是唯一真正有效的答案。謝謝。 – David 2014-09-10 12:31:13

0

讓你的佈局的背景是這樣的:android:background="@drawable/shape"

0

剛剛從你的形狀刪除<solid>標籤。然後將該形狀應用於您的LinearLayout的背景。

因爲<solid>標記指定了形狀的填充顏色。 沒有這個標籤,你的形狀的中心將是完全透明的。 所以它看起來就像一個邊框。

0

下面的xml文件

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

    <stroke 
     android:width="1dp" 
     android:color="#4a6176" /> 

    <padding 
     android:left="10dp" 
     android:right="10dp" 
     /> 

    <corners android:radius="6dp" /> 

</shape> 
+0

它不起作用,內容與形狀重疊。 – David 2014-09-10 12:27:08