Android 未定义layoutweight属性时,视图将消失
我有布局(列表项): 但我明白了Android 未定义layoutweight属性时,视图将消失,android,android-layout,Android,Android Layout,我有布局(列表项): 但我明白了 [ 1 ] [2][ 3 ] 4和5不可见(不适合屏幕) 当我添加layout\u weight=“1”时,它会起作用,但我不知道为什么: <TextView android:id="@+id/event" android:layout_width="match_parent" android:layout_height="wrap_content" android:ellipsize
[ 1 ]
[2][ 3 ]
4和5不可见(不适合屏幕)
当我添加layout\u weight=“1”
时,它会起作用,但我不知道为什么:
<TextView
android:id="@+id/event"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:maxLines="2"
android:text="Text text text"
android:textColor="@color/text"
android:textSize="14sp"
android:layout_weight="1" />
更换此
android:layout_width="match_parent"
借
对于urtextview
@+id/event
您指定了textview
宽度以匹配父项,因此它将占用所有宽度,因此4和5不可见
编辑:
<?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="74dp"
android:background="#ffffff"
android:orientation="vertical" >
<View
android:id="@+id/event_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:background="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="73dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="5" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
<TextView
android:id="@+id/event"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:ellipsize="marquee"
android:maxLines="2"
android:text="Text text text"
android:textColor="#000000"
android:textSize="14sp" />
<TextView
android:id="@+id/event_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="14dp"
android:layout_marginRight="14dp"
android:layout_weight="1"
android:gravity="center|right"
android:maxLines="2"
android:text="2014.05.13\n16.20:33"
android:textColor="#000000"
android:textSize="10sp" />
<ImageView
android:id="@+id/event_delete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
如果您希望按照您指定的方式使用,则最好为第二个
线性布局中的所有视图指定android:layout\u权重
,并设置android:layout\u width=“0dp”
,如下所述:
它不起作用,因为我不知道@+id/event
中文本的大小检查我的编辑部分我添加了带权重的xml代码…在你的问题中,你问了原因..你也应该给相对布局加权重..权重不平衡..你还应该给父布局加权重和。。检查我的ans权重总和将布局除以5个权重。权重之和是布局视图为5…这有助于设计兼容性。。。
android:layout_width="match_parent"
android:layout_width="wrap_content"
<?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="74dp"
android:background="#ffffff"
android:orientation="vertical" >
<View
android:id="@+id/event_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:background="#000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="73dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="5" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
<TextView
android:id="@+id/event"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:ellipsize="marquee"
android:maxLines="2"
android:text="Text text text"
android:textColor="#000000"
android:textSize="14sp" />
<TextView
android:id="@+id/event_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="14dp"
android:layout_marginRight="14dp"
android:layout_weight="1"
android:gravity="center|right"
android:maxLines="2"
android:text="2014.05.13\n16.20:33"
android:textColor="#000000"
android:textSize="10sp" />
<ImageView
android:id="@+id/event_delete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="73dp"
android:gravity="center_vertical">
<RelativeLayout
android:layout_width="65dp"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
<TextView
android:id="@+id/event"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:maxLines="2"
android:text="Text text text"
android:textColor="@color/text"
android:textSize="14sp" />
<TextView
android:id="@+id/event_time"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:maxLines="2"
android:text="2014.05.13\n16.20:33"
android:textColor="@color/text_faded"
android:textSize="10sp"
android:gravity="center|right"
android:layout_marginRight="14dp"
android:layout_marginEnd="14dp"/>
<ImageView
android:scaleType="fitCenter"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/event_delete"
android:src="@drawable/ic_delete" />
</LinearLayout>