Sal*_*jad 5 android android-layout
如何删除此警告?
使用layout_height为0dip而不是wrap_content可以获得更好的性能
Lal*_*ani 22
好的让我通过一个例子解释一下,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hello World!!" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,我使用的android:layout_weight="1"是TextView,我告诉布局我的TextView将采用父布局(LinearLayout)的全高度.因此,在这种情况下android:layout_height="wrap_content"没有用,因为TextView将具有作为父级的完整大小LinearLayout.因此,在这种情况下,最好添加android:layout_height="0dp"以使TextView将自身换行到父布局的高度.
您必须在垂直父布局中存在的子元素中具有 uselayout_weight属性。因此,在这种情况下,您已经告诉父级要向子级应用多少高度。
所以在子元素中替换
android:layout_height="wrap_content"
Run Code Online (Sandbox Code Playgroud)
和
android:layout_height="0dp"
Run Code Online (Sandbox Code Playgroud)
然而,这只是一个猜测,您应该发布整个布局 XML