Android GridView中的额外空间
我试图删除gridview中图像之间显示的额外空间 我的XML文件具有以下格式:Android GridView中的额外空间,android,android-layout,android-gridview,android-gridlayout,Android,Android Layout,Android Gridview,Android Gridlayout,我试图删除gridview中图像之间显示的额外空间 我的XML文件具有以下格式: <FrameLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <GridView android:id="@+id/ga
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<GridView
android:id="@+id/gallery_grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:stretchMode="columnWidth" />
</FrameLayout>
注意:我尝试更改horizontalSpacing属性中的值,但这似乎没有任何作用。我希望图像在纵向模式下显示为2列,在横向模式下显示为3列。我不想要的是图像之间浪费的空间。我希望将它们拉伸并移除浪费的空间。尝试以下方法:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<GridView
android:id="@+id/gallery_grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="2"
android:stretchMode="columnWidth" />
</FrameLayout>
你要求系统用2列填充所有屏幕,因此我认为他覆盖了属性android:horizontalSpacing。这就是神奇之处:
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
在GridView适配器的getView方法中。增加“宽度”、“高度”值以满足您的要求
<GridView
android:id="@+id/gallery_grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:clickable="true"
android:columnWidth="100dp"
android:drawSelectorOnTop="true"
android:focusable="true"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp" />
增加GridView中项目的宽度是否也创建了横向布局?是否可以放置griditem布局文件?尝试设置GridView宽度包装内容。