2012-09-13 42 views
3

這就是我想要的:如何實現帶圓角的桌子?

enter image description here

這是我做了什麼:

enter image description here

的區別是有線條和邊框之間的一些空間,因爲我用padding=10dp外邊框:

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/> 
    <stroke android:width="2dp" android:color="#808080"/> 
    <corners 
      android:radius="10dp"/> 
    <padding 
      android:left="10dp" 
      android:top="10dp" 
      android:right="10dp" 
      android:bottom="10dp"/> 
</shape> 

我做對了嗎?我該如何解決這個問題?

+0

嘗試刪除填充。 –

回答

4

這是您想要的xml文件。

從您的xml文件中刪除填充並在每個小部件中填充填充。這裏的test.xml是你的背景xml文件,不帶填充屬性。

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_gravity="center_horizontal" 
     android:background="@drawable/test" 
     android:layout_margin="10dp"> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Sample TextView" 
      android:padding="10dp"/> 

     <View 
      android:layout_width="fill_parent" 
      android:layout_height="2dp" 
      android:background="#000000" /> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="Sample TextView" 
      android:padding="10dp"/> 

     </LinearLayout> 

編輯的test.xml文件

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#FFFFFF"/> 
    <stroke android:width="2dp" android:color="#808080"/> 
    <corners 
      android:radius="10dp"/> 

</shape> 

enter image description here

1

刪除填充。將元素放入每個框中並將填充添加到每個框中。

1

解決方案1: //去掉填充的形狀

解決方案2: //保持填充,因爲它是

,並把保證金爲您的觀點,即該行你繪製爲水平線

android:marginLeft="-10dp" 
android:marginRight="-10dp" 

//用於頂一個

android:marginTop="-10dp" 
+1

So2看起來很有趣,謝謝! – Freewind