2017-06-06 2 views
0

Ich versuche, diese Ansicht zu erstellen:RecyclewView mit verschachtelten Grid Höhe einstellen

enter image description here

Es ist Rerecyclew mit einem Gridview für jedes Element. Also, wenn Sie das Plus-Element drücken, muss ich ein neues Element an die Gridview hinzufügen und die RecyclewView Artikel Höhe anpassen.

Aber ich kann es nicht mit einer wrap_content machen und ich weiß nicht warum.

Aktivität Layout-

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/rv_scenes" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical" /> 

</LinearLayout> 

RecyclewView Artikel

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <GridView 
     android:id="@+id/gv_scene_items" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:numColumns="3" 
     android:gravity="center" 
     android:columnWidth="50dp" /> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="#eaeaea" /> 

</LinearLayout> 

Grid Artikel (nur zum Beispiel)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="55dp" 
    android:layout_height="55dp" 
    android:background="@color/liloColorBlue"> 



</LinearLayout> 

Können Sie mir helfen, die Beispielansicht zu erhalten?

Vielen Dank.

Antwort

0

fand ich die Lösung meiner eigenen Gridview wie folgt zu schaffen:

public class ScenesGridView extends GridView { 

     public ScenesGridView(Context context, AttributeSet attrs) { 
      super(context, attrs); 
     } 

     public ScenesGridView(Context context) { 
      super(context); 
     } 

     public ScenesGridView(Context context, AttributeSet attrs, int defStyle) { 
      super(context, attrs, defStyle); 
     } 

     @Override 
     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
      int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, 
        MeasureSpec.AT_MOST); 
      super.onMeasure(widthMeasureSpec, expandSpec); 
     } 


} 
0

Sie können dies sehr einfach tun. die recyclerView Höhenänderung in xml:

<android.support.v7.widget.RecyclerView 
    android:id="@+id/rv_scenes" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical" /> 

einstellen Dadurch wird automatisch die Layouts.

Hoffe, das hilft.

+0

leider nicht funktioniert –

0

Rufen Sie die notifyDataSetChanged() oder notifyItemChanged(int position) Methoden der RecyclerView.Adapter aus dem MAIN THREAD.

Ich hoffe, das Ihnen helfen kann