2015-09-04 29 views
15

似乎新的百分比支持庫已發佈,但不允許引用維度xml文件中的百分比值。缺少PercentRelativeLayout百分比值的XML資源類型?

也就是說,代替:

<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/> 

能夠像那樣代碼的東西:

<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"/> 

其中myWidthPercent是在資源文件中定義。

我錯了嗎(我是否錯過了另一個名稱)還是我們可以發送給谷歌的功能請求?

+0

你怎麼像我在第一行得到錯誤使用此標記

回答

29

使用分數,而不是百分之

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

和引用它

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

明白了。正是我需要的。謝謝Llya。 – u2gilles