我正在使用 LinearLayout horizontal 从适配器加载 View 。尽管我使用的是 wrap_content 并且布局中的 View 与顶部对齐。并且linearLayout下面有一个空白区域。这是错误还是我做错了什么。请检查附件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clickable="true"
android:background="@drawable/recycler_selector">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="50dp"
android:id="@+id/group_chat_photo" />
<RelativeLayout
android:layout_width="0dp"
android:layout_weight="5"
android:paddingStart="5dp"
android:paddingEnd="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_height="wrap_content"
style="@style/ListTitleTextStyle"
android:id="@+id/group_name" />
<TextView
android:layout_width="wrap_content"
android:padding="5dp"
android:layout_toStartOf="@id/group_name"
android:layout_height="wrap_content"
android:id="@+id/num_of_group_users"
style="@style/PresenceTextStyle"
android:layout_toEndOf="@id/group_name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/SubTitleTextStyle"
android:layout_below="@id/group_name"
android:id="@+id/group_members_presence"/>
</RelativeLayout>
<ImageView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:src="@drawable/ic_dots_vertical_grey600_24dp"
android:contentDescription="@string/group_chat_options"
android:id="@+id/group_chat_options"/>
</LinearLayout>
最佳答案
不要将 LinearLayout
属性 android:layout_weight
用于 RelativeLayout
。
我用 RelativeLayout
重新设计了您的 xml。请参阅附件图像以获取输出。
这是工作代码。试试这个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="82dp"
android:clickable="true"
android:background="#455A64"
android:padding="16dp">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/group_chat_photo"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:src="@mipmap/ic_launcher"/>
<ImageView
android:id="@+id/group_chat_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/ic_dots_vertical_grey600_24dp"
android:contentDescription="group_chat_options" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/group_chat_photo"
android:layout_toLeftOf="@id/group_chat_options"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp">
<TextView
android:id="@+id/group_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Americal AllStars"
android:textColor="#FFFFFF"
android:textSize="18dp"/>
<TextView
android:id="@+id/group_members_presence"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/group_name"
android:text="Alucard, Client"
android:textColor="#0788C9"
android:textSize="16dp" />
<TextView
android:id="@+id/num_of_group_users"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/group_members_presence"
android:layout_alignBottom="@id/group_members_presence"
android:paddingLeft="5dp"
android:text="and 10 others"
android:textColor="#0788C9"
android:textSize="16dp" />
</RelativeLayout>
</RelativeLayout>
输出:
希望对你有帮助~
关于android - 底部有空白的 LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43187746/