2016-08-06 12 views
1

Das ist dummes Problem, aber ich konnte nicht finden, was ich falsch mache.Unerwarteter Platz kommt in Recyclerview items

Ich benutze FirebaseRecyclerAdapter, um RecyclerView zu füllen, aber es gibt unerwarteten Platz kommt mit Elementen. enter image description here

Fragment Klasse:

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_tags, container, false); 

    mProgressBar = (ProgressBar)view.findViewById(R.id.progressBar); 
    mTagsRecyclerView = (RecyclerView) view.findViewById(R.id.tagsRecyclerView); 
    mLinearLayoutManager = new LinearLayoutManager(getContext()); 

    mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference(); 
    mFirebaseAdapter = new FirebaseRecyclerAdapter<Tags, TagsViewHolder>(
      Tags.class, 
      R.layout.item_message, 
      TagsViewHolder.class, 
      mFirebaseDatabaseReference.child("tags")) { 

     @Override 
     protected void populateViewHolder(TagsViewHolder viewHolder, Tags tags, int position) { 
      mProgressBar.setVisibility(ProgressBar.INVISIBLE); 
      viewHolder.tagTextView.setText(tags.getTagname()); 
      viewHolder.usrTextView.setText(tags.getUserid()); 
     } 
    }; 


    mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { 
     @Override 
     public void onItemRangeInserted(int positionStart, int itemCount) { 
      super.onItemRangeInserted(positionStart, itemCount); 
     } 
    }); 

    mTagsRecyclerView.setLayoutManager(mLinearLayoutManager); 
    mTagsRecyclerView.setAdapter(mFirebaseAdapter); 

    mTagsRecyclerView.addOnItemTouchListener(new RecyclerViewItemClickListener(getContext(), 
      new RecyclerViewItemClickListener.OnItemClickListener() { 
       @Override public void onItemClick(View v, int position) { 
        //TODO: 
        // do something on item click 
        Log.d("Item clicked at",Integer.toString(position)); 
       } 
      })); 
    return view; 
} 

Fragment Layout:

<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.helpplusapp.amit.helpplus.TagsFragment"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/tagsRecyclerView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    /> 
<ProgressBar 
    style="?android:attr/progressBarStyleSmall" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/progressBar" 
    android:layout_gravity="center" 
    /> 

Liste item Layout:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:divider="@drawable/view_separator" 
    android:paddingTop="@dimen/margin_default" 
    android:paddingBottom="@dimen/margin_default" 
    android:showDividers="end"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:id="@+id/tagTextView" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:id="@+id/usrTextView" 
      /> 

</LinearLayout> 

Bitte vorschlagen.

Antwort

6

In listitemlayout XML-Datei die Höhe der linearen Layout machen Inhalt

+0

Ja, es ist richtig..danke viel @Moulesh –

1

In Listenelement-Layout ändern, um die lineare Layout android einzuwickeln: height = "wrap_content"

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:divider="@drawable/view_separator" 
android:paddingTop="@dimen/margin_default" 
android:paddingBottom="@dimen/margin_default" 
android:showDividers="end"> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:id="@+id/tagTextView" 
     /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:id="@+id/usrTextView" 
     /> 
</LinearLayout> 
+0

Gotcha ... danke –

1

Mit der Unterstützung Bibliothek 23,2 google eingeführt ein Wechsel zum Recyclerview:

LayoutManager API: automatische Messung! Dadurch kann sich ein RecyclerView zu Größe basierend auf der Größe seines Inhalts. Dies bedeutet, dass zuvor nicht verfügbare Szenarien, wie die Verwendung von WRAP_CONTENT für eine Dimension des RecyclerView, jetzt möglich sind. Sie werden feststellen, dass alle eingebauten in LayoutManager jetzt automatische Messung unterstützen. Aufgrund dieser Änderung, stellen Sie sicher, die Layout-Parameter Ihrer Artikel Ansichten zu überprüfen: zuvor ignoriert Layout-Parameter (wie MATCH_PARENT in der Scroll-Richtung) werden nun vollständig eingehalten.

Source

Sie müssen die Höhe des Elements ändern, anstatt match_parent wrap_content.

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:divider="@drawable/view_separator" 
    android:paddingTop="@dimen/margin_default" 
    android:paddingBottom="@dimen/margin_default" 
    android:showDividers="end"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:id="@+id/tagTextView" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:id="@+id/usrTextView" 
      /> 

</LinearLayout>