2010-09-09 5 views
15

वहाँ एक ढाल के लिए एक ऊपर और नीचे स्ट्रोक निर्धारित करें, या बनाने के लिए एक यौगिक आकार drawable ?:आयताकार आकार खींचने योग्य, ऊपर और नीचे स्ट्रोक रंग निर्दिष्ट करें?

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

    <gradient 
    android:startColor="#f00" 
    android:endColor="#0f0" 
    /> 
    <stroke 
    top=1dip, yellow 
    bottom=1dip, purple 
    /> 
</shape> 

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

    <shape 
    android:shape="rectangle" 
    height=1dip, color=yellow /> 

    <gradient 
    android:startColor="#f00" 
    android:endColor="#0f0" 
    /> 

    <shape 
    android:shape="rectangle" 
    height=1dip, color=purple /> 
</shape> 

मुझे नहीं लगता कि या तो संभव हो रहे हैं कोई तरीका है?

धन्यवाद

+0

करने के लिए 3 से आइटम की संख्या को कम देखते हैं कि यह: http://stackoverflow.com/questions/1598119/is-there-an-easy-way-to-add- एक-सीमा-से-द-टॉप-एंड-डाउन-ऑफ-एंड-एंड्रॉइड-व्यू – Kenumir

उत्तर

10

मुझे लगता है, यह layer-list का उपयोग करके किया जा सकता है।

बाद रेस/drawable/layer_list_shape.xml
मैं का इस्तेमाल किया है हार्ड-कोडेड आयाम है ..

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
<item> 
    <shape android:shape="rectangle"> 
     <size android:width="150dp" android:height="6dp"/> 
     <solid android:color="#ff0" /> 
    </shape> 
</item> 
<item android:top="6dp"> 
    <shape android:shape="rectangle" > 
     <size android:width="150dp" android:height="50dp"/> 
     <gradient 
      android:endColor="#0f0" 
      android:startColor="#f00" /> 
    </shape> 
</item> 
<item android:top="82dp"> 
    <shape android:shape="rectangle" > 
     <size android:width="150dp" android:height="6dp"/> 
     <solid android:color="#ff0" /> 
    </shape> 
</item> 

रेस/लेआउट/main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 
<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/layer_example" /> 
</LinearLayout> 

उम्मीद है कि यह मदद करता है ..

0

आप हार्डकोडेड आयामों का उपयोग करने के लिए नहीं करना चाहते हैं यह 3 दृश्यों का उपयोग करने के लिए संभव है:

<LinearLayout 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="@android:color/black" > 

<View 
    android:layout_width="match_parent" 
    android:layout_height="1dip" 
    android:background="@android:color/white"/> 

<TextView 
    android:id="@+id/header" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    style="@style/header" /> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="1dip" 
    android:background="@android:color/white"/> 

</LinearLayout> 

हैडर तत्व एक ढाल पृष्ठभूमि है। बेशक, आप किसी अन्य लेआउट का भी उपयोग कर सकते हैं।

1

विजय सी द्वारा दिए गए उत्तर पर निर्माण, आप किसी भी लेआउट में एक ड्रायबल और शामिल कर सकते हैं। पिछला जवाब ठीक था लेकिन इसमें हार्ड-कोड किए गए आयाम जोड़े गए जो पृष्ठभूमि में wrap_content के रूप में उपयोग करना असंभव बना दिया। इसके अलावा, इस तरह से आप 2.

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape android:shape="rectangle"> 
      <solid android:color="#d8dae3" /> 
     </shape> 
    </item> 
    <item 
     android:bottom="2dp" 
     android:top="2dp"> 
     <shape android:shape="rectangle"> 
      <gradient 
       android:endColor="@android:color/white" 
       android:startColor="@android:color/white" /> 
     </shape> 
    </item> 
</layer-list> 
+0

धन्यवाद, इससे मदद मिली। – hue23289

संबंधित मुद्दे