android - GridView 中的矩形图像

标签 android android-layout android-xml

如何创建图像为矩形 (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/

相关文章:

android - ListView 使用两个光标适配器?

android - android中的方形边缘不确定进度条

android - 使用 fragment 将图像添加到选项卡

android - 在android中将 View 转换为图像

android - 如何获取android系统默认家庭应用程序的名称

android - onresume fragment 中 View 为空

android - 如何从服务器删除已经上传的图片文件?

java - 计算我 dp 出错的高度

android - 导航栏中的项目未显示

android - RecyclerView 不是真正的 wrap_content 在 ScrollView