1

Ich möchte ein Layout erstellen, das mehrere Elemente anzeigen, aber ich kann sie nicht vollständig entfalten, also verwende ich eine ScrollView. Ich finde jedoch, dass ich nur die erste GridView scrollen kann, die letzten zwei Elemente können nicht nach oben scrollen. Was ich brauche ist, zwei GridView vollständig anzuzeigen und alle Elemente können gescrollt werden, aber ich weiß nicht, wie ich mit dem Problem umgehen soll.Scroll LinearLayout in ScrollView nicht scrollen

<RelativeLayout 
    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="match_parent" 
    tools:context="com.ifchan.reader.AllClassActivity"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/all_class_tool_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/colorToolbar" 
     app:title="All Class" 
     app:titleTextColor="#ffffff"/> 

    <ScrollView 
     android:id="@+id/all_class_scroll_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/all_class_tool_bar" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 


      <TextView 
       android:id="@+id/all_class_male" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="male" 
       android:textSize="20dp"/> 

      <GridView 
       android:id="@+id/all_class_male_grid_view" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:horizontalSpacing="10dp" 
       android:numColumns="auto_fit" 
       android:stretchMode="columnWidth" 
       android:verticalSpacing="10dp"/> 

      <TextView 
       android:id="@+id/all_class_female" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="female" 
       android:textSize="20dp"/> 

      <GridView 
       android:id="@+id/all_class_female_grid_view" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:horizontalSpacing="10dp" 
       android:numColumns="auto_fit" 
       android:stretchMode="columnWidth" 
       android:verticalSpacing="10dp"/> 


     </LinearLayout> 

    </ScrollView> 

</RelativeLayout> 

Antwort

0
Use Recycler View or a non scrollable gridview if you want to use scrollview. 

    public class NonScrollGridView extends GridView{ 

     public NonScrollGridView (Context context) { 
      super(context); 
     } 
     public NonScrollGridView (Context context, AttributeSet attrs) { 
      super(context, attrs); 
     } 
     public NonScrollGridView (Context context, AttributeSet attrs, int defStyle) { 
      super(context, attrs, defStyle); 
     } 
     @Override 
     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
      int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
        Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); 
      super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom); 
      ViewGroup.LayoutParams params = getLayoutParams(); 
      params.height = getMeasuredHeight(); 
     } 



    <NonScrollGridView 
        android:id="@+id/all_class_female_grid_view" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:horizontalSpacing="10dp" 
        android:numColumns="auto_fit" 
        android:stretchMode="columnWidth" 
        android:verticalSpacing="10dp"/> 
0

Sie setzen Grid s in ScrollView. Es wird nicht wie erwartet funktionieren.

Versuchen GridLayoutManager mit RecyclerView verwenden und sie in NestedScrollView

Sie this Frage für ausführliche Erklärungen überprüfen.

Wenn Sie wollen Gridview trotzdem verwenden, können Sie diese ExpandableHeightGridView verwenden, die Gridview erweitert

+0

Ich möchte nur voll in zwei Grid alle Einträge anzuzeigen, kann ich es einfacher zu machen? – IfChan

+0

@IfChan hat meine Antwort aktualisiert und die GridView-Option für Sie hinzugefügt. –

Verwandte Themen