gpt4 book ai didi

android - GridView 中的矩形图像

转载 作者:行者123 更新时间:2023-11-29 00:36:58 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com