我正在尝试支持库中的 PercentRelativeLayout,并且the docs http://developer.android.com/reference/android/support/percent/PercentRelativeLayout.html只需让我指定一个 app:layout_widthPercent 属性即可。然而,当我这样做时,Android Studio 会给我一个红色警告,指出布局宽度未指定。
除了抑制警告之外,还有其他办法吗?
例如:
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="@+id/expiry_month_wrapper"
app:layout_widthPercent="25%"
android:layout_height="wrap_content">
<EditText
android:id="@+id/expiry_month_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="2"
android:hint="@string/month"
android:focusable="true"
android:inputType="number"/>
</android.support.design.widget.TextInputLayout>
<!-- more TextInputLayout fields -->
</android.support.percent.PercentRelativeLayout>
TextInputLayout 上发出警告。
按照惯例,即使在功能上分别被 PercentRelativeLayout 的 app:layout_widthPercent 和 app:layout_aspectRatio 忽略时,也需要包含layout_width 和layout_height。
在您的情况下,仅使用 app:layout_widthPercent,只需将 android:layout_width 设置为任意数量的与密度无关的像素即可消除警告。
例如:
安卓:layout_width =“0dp”
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)