2016-04-20 10 views
2
<layer-list 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 
<!--width here doesn't work--> 
<item 
    android:gravity="left" 
    android:width="10dp" 
    > 
    <shape 
     android:shape="rectangle" 
    > 
     <stroke 
      android:width="1dp" 
      android:color="@color/black" 
     /> 
     <!--<gradient--> 
      <!--android:startColor="#00dddddd"--> 
      <!--android:endColor="#40404040"--> 
      <!--android:angle="0"--> 
      <!--/>--> 
    </shape> 
</item> 
<!--width here doesn't work--> 
<item 
    android:width="10dp" 
    android:gravity="right" 
    > 
    <shape 
     android:shape="rectangle" 
    > 
     <stroke 
      android:width="1dp" 
      android:color="@color/black" 
     /> 
     <!--<gradient--> 
      <!--android:startColor="#00dddddd"--> 
      <!--android:endColor="#40404040"--> 
      <!--android:angle="180"--> 
      <!--/>--> 
    </shape> 
</item> 

Android: in Zeichnungs-XML, Layer-Liste, warum funktioniert die Breite für Artikel nicht in API 19 oder niedriger?

ist hier das Beispiel.

Es funktioniert in Lollipop oder höher, aber es funktioniert nicht in Kitkat, die Breite wird ignoriert, das Rechteck füllt die gesamte Ansicht.

Ich habe auch versucht, das zweite Element zu entfernen, hinterlässt nur das erste Element, die Breite wird immer noch ignoriert.

Der Image verwendet dieses ziehbar:

<!--Width will be changed dynamically--> 
<ImageView 
    android:id="@+id/someid" 
    android:layout_width="100dp" 
    android:layout_height="@dimen/someheight" 
    android:src="@drawable/the_xml_above" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:clickable="false" 
    /> 

Wie dieses Problem zu lösen?

Antwort

4

Okay, werde ich meine eigene Frage beantworten:

Es scheint, dass auf Android 4.4 oder unten, Größe Knoten oder Breite/Höhe Attribut wird ignoriert.
Der beste Ansatz ist also: Erstellen Sie verschiedene Formen in verschiedenen XML-Dateien, erstellen Sie ein relatives Layout anstelle von ImageView und kombinieren Sie sie in einem relativen Layout.

<RelativeLayout 
    android:id="@+id/id1" 
    android:layout_width="30dp" 
    android:layout_height="@dimen/someheight" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:clickable="false"> 

    <ImageView 
     android:layout_width="3dp" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:src="@drawable/somesrc"/> 

    <ImageView 
     android:layout_width="3dp" 
     android:layout_height="match_parent" 
     android:layout_alignParentRight="true" 
     android:rotation="180" 
     android:src="@drawable/somesrc"/> 

</RelativeLayout> 
Verwandte Themen