2015-09-04 6 views
15

Es scheint, dass die neue Bibliothek für die prozentuale Unterstützung veröffentlicht wurde, ohne dass ein Prozentwert in einer XML-Dimensionsdatei referenziert werden konnte.Fehlender XML-Ressourcentyp für PercentRelativeLayout Prozentsatz?

Das heißt, statt:

<android.support.percent.PercentRelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
    <ImageView 
     app:layout_widthPercent="50%" 
     app:layout_heightPercent="50%" 
     app:layout_marginTopPercent="25%" 
     app:layout_marginLeftPercent="25%"/> 
</android.support.percent.PercentFrameLayout/> 

der Lage sein, so etwas zu kodieren:

<android.support.percent.PercentRelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 
<ImageView 
    app:layout_widthPercent="@percent/myWidthPercent" 
    app:layout_heightPercent="@percent/my/HeightPercent" 
    app:layout_marginTopPercent="@percent/myMarginTophPercent" 
    app:layout_marginLeftPercent="@percent/myMarginLeftPercent"/> 

wo myWidthPercent in einer Ressource-Dateien definiert ist.

Bin ich falsch (habe ich es mit einem anderen Namen vermisst) oder ist es eine Feature-Anfrage, die wir an Google senden könnten?

+0

wie verwenden Sie diese Tags als i Störung erhalten in erster Zeile

Antwort

29

Verwenden Fraktion statt Prozent

<resources> 
    <fraction name="myWidthPercent">50%</fraction> 
... 
</resources> 

Und verweist auf es

<ImageView 
    app:layout_widthPercent="@fraction/myWidthPercent" 
    app:layout_heightPercent="@fraction/my/HeightPercent" 
    app:layout_marginTopPercent="@fraction/myMarginTophPercent" 
    app:layout_marginLeftPercent="@fraction/myMarginLeftPercent"/> 
+0

Bekam es. Genau das, was ich brauchte. Danke, Llya. – u2gilles

Verwandte Themen