Answer the question
In order to leave comments, you need to log in
Android - How to calculate the height of a GridView?
Let's say we have a populated GridView with auto-fit columns (auto_fit) that is in a ScrollView. I set the layout_height="wrap_content" parameter, but the height of the list turns out to be equal to the height of one element, and I need it to shrink to a size that will fit the entire list.
Markup code:
<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="match_parent" tools:context="ru.redo.zona.MainTabFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_container">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_popularmovies"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:id="@+id/main_popularmovies_title">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/main_topfilms"
android:id="@+id/main_popularmovies_titleText"/>
</LinearLayout>
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_popularmovies_list"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp"
android:numColumns="auto_fit"
android:horizontalSpacing="10dp"
android:columnWidth="@dimen/cover_width"
android:gravity="center"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question