サーバーからのデータをページングするScrollView内のLinearLayout内にGridViewがあります。GridViewの下には、より多くのデータをロードするためのボタンがあります。私のGridViewの最終的な高さは、画面よりも大きくなります。GridViewの高さをwrap_contentまたはparent_fillのいずれかに設定すると、画面上で使用可能な正確な高さにサイズ変更され、まったくスクロールせず、余分な行が切り取られます。layout_heightを1000dipなどの大きな値に明示的に設定すると、スクロールは適切に動作しますが、スクロールビューの最終的な高さを事前に予測することはできません。
目的の動作を実現するために必要なGridViewの高さをプログラムで決定するにはどうすればよいですか?
これが私のレイアウトです。ご覧のとおり、高さを1000dipに設定しましたが、それは偽物です。自動的に/プログラムで設定するには、その値が必要です。
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:layout_weight="1"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="1000dip"
android:columnWidth="70dp"
android:numColumns="auto_fit"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#000000"
android:layout_weight="1"
/>
<Button
android:id="@+id/load_more"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Load More Foo"
/>
</LinearLayout>
</ScrollView>