PercentRelativeLayout百分比值缺少XML资源类型? [英] Missing XML resource type for PercentRelativeLayout Percentage value?
本文介绍了PercentRelativeLayout百分比值缺少XML资源类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎发布了新的百分比支持库,但不允许在维度xml文件中引用百分比值.
It seems that the new Percent Support Library was released without allowing to reference a Percentage value in a dimension xml file.
也就是说,而不是:
<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在资源文件中定义.
where myWidthPercent is defined in a resource files.
我错了吗(我想念另一个名字吗)还是我们可以发送给Google的功能请求?
Am i wrong (did i miss it with another name) or is it a feature request that we could send to google?
推荐答案
使用分数代替百分比
<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"/>
这篇关于PercentRelativeLayout百分比值缺少XML资源类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文