2017-04-03 120 views
0

我正在使用LinearLayout水平从适配器加载视图。虽然我正在使用wrap_content,并且布局中的视图都对齐到顶部。 linearLayout下面有一个空白区域。这是一个错误,或者我做错了什么。请检查连接screenshot带底部空白的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> 
+0

也许有一些错误的适配器?不要认为你的问题在LinearLayout中。它是一个RecyclerView适配器吗? –

+0

你可以请你发布你的适配器类吗? – FAT

+0

@Contextioner在下面看到我的答案。我重新设计了你的xml。输出见附图。谢谢 – FAT

回答

0

请勿使用LinearLayout属性android:layout_weightRelativeLayout。 我用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> 

OUTPUT:

enter image description here

希望这将帮助你〜

+0

@Contextioner如果我的回答看起来有用,请投票赞成。提前致谢 :) – FAT

0

这个元素是最主要的问题,

<TextView 
    android:id="@+id/num_of_group_users" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toEndOf="@id/group_name" 
    android:layout_toStartOf="@id/group_name" 
    tools:text="10 users" 
    android:padding="5dp" /> 

因为,你已经在使用相对布局,也没有必要来包装这个局面线性布局。您可以使用单个RelativeLayout作为容器。例如,以下只是想法,您可以根据需要更改填充和边距。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@android:color/holo_orange_dark" 
    android:orientation="horizontal"> 

    <ImageView 
    android:id="@+id/group_chat_photo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:src="@mipmap/ic_launcher" /> 

    <TextView 
    android:id="@+id/group_name" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/group_chat_photo" 
    tools:text="Some title" /> 

    <TextView 
    android:id="@+id/num_of_group_users" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/group_name" 
    android:layout_toRightOf="@+id/group_members_presence" 
    tools:text="10 users" /> 

    <TextView 
    android:id="@+id/group_members_presence" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/group_name" 
    android:layout_toRightOf="@+id/group_chat_photo" 
    tools:text="Presence" /> 

    <ImageView 
    android:id="@+id/group_chat_options" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:src="@mipmap/ic_launcher" /> 

</RelativeLayout> 
0

尝试把整个线布局在另一个布局(相对或线性),其宽度为“match_parent”和高度设置为“WRAP_CONTENT”

0

我觉得问题是有你在哪里使用layout_toStartOf和layout_toEndOf在一个TextView中(android:id =“@ + id/num_of_group_users”)删除其中一个。