如何创建图像为矩形 (120 x 58.5) 的 GirdView,这会导致非方形单元格?目前,如果我有这个 XML 布局,则图像上方和下方有空白,因为单元格为 120 x 120。每个单元格的宽度应为 120,高度应为 58。
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/AppsOverviewGrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="120dp"
android:numColumns="auto_fit"
android:verticalSpacing="0dp"
android:horizontalSpacing="8dp"
android:stretchMode="columnWidth"
android:gravity="center">
</GridView>
感谢您的帮助。
最佳答案
在我看来,理想的解决方案是为 gridview 布局中的项目创建一个布局文件,您可以在其中指定图像的高度(使用 ImageView)。然后,您可以使用带有 LayoutInflater 的自定义适配器将 GridView 项与主布局连接起来。
这是一个很棒的教程(2.示例):http://www.mkyong.com/android/android-gridview-example/
关于android - GridView 中的矩形图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12087770/