2015-09-04 98 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