PercentRelativeLayout - layout_width 缺少警告
PercentRelativeLayout - layout_width missing warning
我正在试用支持库中的 PercentRelativeLayout,the docs 只是让我指定一个 app:layout_widthPercent 属性。但是,当我这样做时,Android Studio 给我一个红色警告,说 layout_width 未指定。
除了抑制警告之外,还有其他解决方法吗?
例如:
<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 设置为任意数量的密度无关像素即可消除警告。
例如:
android:layout_width = "0dp"
我意识到这是一个老问题 - 但刚刚遇到这个问题我想确保它对每个人都可用:)
向 PercentRelativeLayout
添加视图会在文本编辑器中引发视觉错误。它甚至可能无法在屏幕上呈现。继续 运行 你的模拟器,它应该可以解决可见性问题。
要解决该错误,只需添加 android:layout_width="0dp"
只要您的 widthPercent
和 heightPercent
设置正确,您就不会遇到问题。
这是我的测试代码示例
android:text="Label label"
android:id="@+id/btn1"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_alignParentTop="true"
app:layout_widthPercent="50%"
app:layout_heightPercent="30%"
android:textSize="17sp"/>
<Button
android:text="Other other other"
android:id="@+id/btn2"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_toRightOf="@id/btn1"
app:layout_widthPercent="50%"
app:layout_heightPercent="30%"
android:textSize="17sp"/>
我正在试用支持库中的 PercentRelativeLayout,the docs 只是让我指定一个 app:layout_widthPercent 属性。但是,当我这样做时,Android Studio 给我一个红色警告,说 layout_width 未指定。
除了抑制警告之外,还有其他解决方法吗?
例如:
<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 设置为任意数量的密度无关像素即可消除警告。
例如: android:layout_width = "0dp"
我意识到这是一个老问题 - 但刚刚遇到这个问题我想确保它对每个人都可用:)
向 PercentRelativeLayout
添加视图会在文本编辑器中引发视觉错误。它甚至可能无法在屏幕上呈现。继续 运行 你的模拟器,它应该可以解决可见性问题。
要解决该错误,只需添加 android:layout_width="0dp"
只要您的 widthPercent
和 heightPercent
设置正确,您就不会遇到问题。
这是我的测试代码示例
android:text="Label label"
android:id="@+id/btn1"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_alignParentTop="true"
app:layout_widthPercent="50%"
app:layout_heightPercent="30%"
android:textSize="17sp"/>
<Button
android:text="Other other other"
android:id="@+id/btn2"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_toRightOf="@id/btn1"
app:layout_widthPercent="50%"
app:layout_heightPercent="30%"
android:textSize="17sp"/>