【问题标题】:Missing XML resource type for PercentRelativeLayout Percentage value?PercentRelativeLayout 百分比值缺少 XML 资源类型?
【发布时间】:2015-09-04 11:51:24
【问题描述】:

似乎新的百分比支持库发布时不允许在维度 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 在资源文件中定义。

我错了(我是不是用另一个名字错过了它)还是我们可以发送给谷歌的功能请求?

【问题讨论】:

  • 你如何使用这个标签,因为我在第一行出现错误

标签: android android-resources android-percent-library


【解决方案1】:

使用分数而不是百分比

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

【讨论】:

  • 知道了。正是我需要的。谢谢莉亚。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-10
  • 2019-01-23
  • 2011-03-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多