PercentRelativeLayout margin_percent在某些情况下不起作用

时间:2017-05-10 11:34:11

标签: android layout

Nougat中的xml忽略marginRightPercent。

  <?xml version="1.0" encoding="utf-8"?>
    <android.support.percent.PercentRelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/container"       
    android:layout_width="match_parent" 
    android:layout_height="match_parent">

      <ImageView
            android:layout_alignParentRight="true"
            app:layout_heightPercent="3.45%"
            app:layout_marginRightPercent="5.07%"
            app:layout_marginTopPercent="2.85%"
            app:layout_widthPercent="6.13%"
            android:scaleType="fitCenter"
            android:src="@drawable/action_bar_notification"/>
    .
    .
    .
    .
    .
    </android.support.percent.PercentRelativeLayout>

我的应用中有其他地方没有被忽略,但其他地方没有layout_widthPercent。这在6.0中运行良好,但我认为它是7.0中的一个错误。

1 个答案:

答案 0 :(得分:0)

添加android:layout_marginRight="1dp" - 它可以是任何值。您只需添加它,然后像app:layout_marginRightPercent这样的值将起作用。我不知道为什么 - 从documentation我推断它应该是有效的。

在新项目中我们使用ConstraintLayout,因为自从API 26以来不推荐使用PercentRelativeLayout

相关问题