2012-09-11 143 views
0

我想創建一個如下圖所示的視圖。我的實現有一些linearLayouts。一個帶有自定義drawable的根可以獲得圓角邊緣,然後使用其他兩個文本視圖和視圖分隔線。有沒有更快,更簡單的方法來做到這一點?如何使用圓角和兩個文字視圖創建自定義視圖?

enter image description here

+0

你可以做到這一點通過自定義'@android:風格/ Theme.Dialog' – silentw

+0

@silentw你是說在LinearLayout上使用它? – irobotxxx

+0

不,在活動清單上... – silentw

回答

1

你可以只用1 LinearLayout中,根一個做到這一點。 LinearLayout僅用於訂購其他視圖。所以,你需要做的是使用垂直方向並添加兩個文本視圖。

在第一個上,您將背景色設置爲淺灰色。請記住以引力爲中心,以便將文本放置在文本視圖的中心。

+0

要得到一個分隔符,你可以在它們之間使用一個FrameLayout寬度爲bakcground顏色的黑色和高度相等的1dp – Rodrigo

+0

謝謝!會嘗試。 – irobotxxx

0

我沒有太多時間,只是試圖給一個快速的樣本。這是我對你的問題代碼:

your_main_layout.xml

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/your_bg.xml"> 

    <TextView 
     android:id="@+id/tv1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="my text" /> 

    <View 
     android:id="@+id/seperator 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:layout_below="@+id/tv1" /> 

     <TextView 
     android:id="@+id/tv2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="2nd text here" 
     android:layout_below="@+id/seperator" /> 

</RelativeLayout> 

your_bg.xml

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

    <corners 
     android:radius="5dp" 
     /> 
    <solid android:color="#fff" /> 
    <stroke android:color="#000" /> 

</shape> 
相關問題