2017-04-03 6 views
0

Ich benutze LinearLayout horizontal, um die Ansicht vom Adapter zu laden. Obwohl ich wrap_content verwende und Ansichten innerhalb des Layouts sind nach oben ausgerichtet. Und es gibt ein Leerzeichen unter dem linearenLayout. Ist das ein Fehler oder was mache ich falsch? Bitte prüfe das beigefügte screenshotLinearLayout mit Leerzeichen unten

<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

Vielleicht etwas falsch in dem Adapter ist da? Denken Sie nicht, dass Ihr Problem im LinearLayout ist. Ist es ein RecyclerView-Adapter? –

+0

Können Sie bitte Ihre Adapterklasse posten? – FAT

+0

@Contextioner siehe meine Antwort unten. Ich habe dein XML neu gestaltet. Zur Ausgabe siehe angehängtes Bild. Danke – FAT

Antwort

0

Verwenden Sie nicht LinearLayout Attribut android:layout_weight zu RelativeLayout. Ich habe Ihre XML mit RelativeLayout neu gestaltet. Siehe das angehängte Bild für die Ausgabe.

Hier ist der Arbeitscode. Versuchen Sie folgendes:

<?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

Hope this Sie helfen ~

+0

@Contextioner Wenn meine Antwort nützlich erscheint, geben Sie bitte eine Stimme ab. Danke im Voraus :) – FAT

0

Dieses Element ist das Hauptproblem,

<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" /> 

Da sind Sie bereits relativ Layout verwenden, gibt es keine Notwendigkeit, diese um lineares Layout zu wickeln. Sie können einzelne RelativeLayout als Container verwenden. Zum Beispiel ist folgendes nur eine Idee, Sie können Polsterung und Rand je nach Bedarf ändern.

<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

versuchen, das ganze lineare Layout in einem anderen Layout zu setzen (Relative oder Linear) und seine Breite zu „match_parent“ und Höhe „wrap_content“

0

Ich denke Problem dort ist, wo Sie layout_toStartOf verwenden und layout_toEndOf in einem TextView (android: id = "@ + id/num_of_group_users") Entferne einen von ihnen.

Verwandte Themen