2016-09-30 20 views
-4

i need to create run in my xmlAndroid的形狀XML像下面的圖像

我如何我可以在XML(可繪製文件夾)創建的形狀。

+0

[http://meta.stackoverflow.com/questions/266384/is-it-ok-to-downvote-questions-asking-about-how-to-achieve-something-without-ha](http ://meta.stackoverflow.com/questions/266384/is-it-ok-to-downvote-questions-asking-about-how-to-achieve-something-without-ha) –

回答

1

drawable_line.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
    <gradient 
     android:startColor="@android:color/black" 
     android:centerColor="@android:color/white 
     android:endColor= "@android:color/black" 
     android:angle="360" 
     /> 
</shape> 

在佈局中添加它作爲view

<View 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:layout_marginRight="20dp" 
      android:layout_marginLeft="20dp" 
      android:background="@drawable/drawable_line" /> 
+0

是的,這工作正常。 –

0

在activity_main添加這些:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:gravity="center" 
     android:background="@android:color/black" 
     android:layout_width="match_parent" 
     android:layout_height="80dp"> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="2dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:background="@drawable/line" /> 
    </LinearLayout> 
</LinearLayout> 

,並創建繪製RES文件:

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <gradient 
     android:angle="360" 
     android:centerColor="@android:color/white" 
     android:endColor="@android:color/black" 
     android:startColor="@android:color/black" /> 
</shape>