Я не могу понять, почему мой GridView немного больше, чем предполагалось.Как показано здесь: Изображение проблемы , GridView переходит по экрану и получает скроллер.Но даже когда я ограничиваю размер GridView, он все равно переходит его вертикальную границу и создает скроллер сам по себе.
Как мне сделать так, чтобы GridView оставался в обозначенном пространстве и не создавал скроллер?У меня есть вес для горизонтального и вертикального пространства, горизонталь работает отлично, я думаю.Но по вертикали я не уверен в этом.
Этот код находится в пользовательском адаптере, расширяющем BaseAdapter.Изображения помещаются в frag_grid, который затем помещается в FrameLayout в Activity_board.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(mContext);
imageView.setImageResource(waterImage);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
return imageView;
}
фрагмент_grid.xml
<?xml version="1.0" encoding="utf-8"?>
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="1dp"
android:verticalSpacing="1dp"
android:numColumns="8"
tools:context=".GridFragment" >
</GridView>
activity_board.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/time_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/invite_friend"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="8">
<FrameLayout
android:id="@+id/fragment_container_player"
android:layout_width="0dp"
android:layout_weight="8"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="2">
</LinearLayout>
<FrameLayout
android:id="@+id/fragment_container_opponent"
android:layout_width="0dp"
android:layout_weight="8"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>