如果不允许使用百分比,如何使用使用xml资源的android支持百分比值?

如果不允许使用百分比,如何使用使用xml资源的android支持百分比值?,android,resources,android-support-library,Android,Resources,Android Support Library,我从谷歌找到了这个有趣的库 使用非常简单,只需添加此依赖项 dependencies { compile 'com.android.support:percent:22.2.0' } 这就是代码 <android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.a

我从谷歌找到了这个有趣的库

使用非常简单,只需添加此依赖项

dependencies {
    compile 'com.android.support:percent:22.2.0'
}
这就是代码

<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
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      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
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_widthPercent="@dimen/width_percent"
          app:layout_heightPercent="@dimen/height_percent"
          app:layout_marginTopPercent="@dimen/margin_top_percent"
          app:layout_marginLeftPercent="@dimen/margin_left_percent"/>
    </android.support.percent.PercentFrameLayout>

问题是我想使用资源指定百分比值,但整数、分数、维度和字符串中不允许使用simbol%


当可以使用0到1之间的值并正确使用资源时,为什么要使用0%到100%之间的值-(

您可以这样定义:

<fraction name="width_percent">80%</fraction>
80%

是百分比库的博客。

您可以这样定义:

<fraction name="width_percent">80%</fraction>
80%
是%图书馆的博客