2017-07-21 12 views
0

私の問題はthis questionと非常によく似ていますが、私はOPと違ってをLayoutInflaterに渡しています。私はサポートライブラリ25.3.1を使用しています。ここで私が膨らまてるレイアウトは(LinearLayoutConstarintLayoutを変更しても解決しない)です:RecyclerView children match_parent

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="72dp" 
    android:background="?android:selectableItemBackground" 
    android:clickable="true" 
    tools:layout_editor_absoluteX="0dp" 
    tools:layout_editor_absoluteY="81dp"> 


    <TextView 
     android:id="@+id/list_text_primary" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="8dp" 
     android:layout_marginEnd="16dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginStart="16dp" 
     android:singleLine="true" 
     android:textAppearance="@style/TextAppearance.ListPrimary" 
     app:layout_constraintBottom_toTopOf="@+id/list_text_secondary" 
     app:layout_constraintHorizontal_bias="0.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_chainStyle="packed" 
     tools:ignore="Deprecated" 
     tools:text="list_text_primary"/> 

    <TextView 
     android:id="@+id/list_text_secondary" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginEnd="16dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp" 
     android:layout_marginStart="16dp" 
     android:gravity="center_vertical" 
     android:singleLine="true" 
     android:textAppearance="@style/TextAppearance.ListSecondary" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="1.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/list_text_primary" 
     tools:ignore="Deprecated" 
     tools:text="list_text_secondary"/> 


</android.support.constraint.ConstraintLayout> 

hereが説明するように、私もonCreateViewHolderで手動LayoutParamsを設定しようとしました。私はそれが働いたと思ったが、時々parentは0の幅と高さを持ちます(私はその理由を特定することができません)、子供が見えなくなる原因になります。 debug_screenshotthis answerによると、すでにと呼ばれている時に私が測定したはRecyclerViewです。

答えて

0

アダプタコードを貼り付けると、それよりも優れていますが、これを試すことができます。

WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); 
      Point size = new Point(); 
      windowManager.getDefaultDisplay().getSize(size); 
      holder.yourItemBinding.getRoot().setLayoutParams(new RecyclerView.LayoutParams(size.x, 
        RecyclerView.LayoutParams.WRAP_CONTENT)); 

あなたが結合レイアウトを使用していない場合は、あなたのルートビューオブジェクトと

holder.yourItemBinding.getRoot()

を交換してください。

関連する問題