gpt4 book ai didi

android - 自动调整android中gridview中单元格的大小

转载 作者:行者123 更新时间:2023-11-30 02:38:12 25 4
gpt4 key购买 nike

我正在使用 android 中的 gridview 开发自定义图库。现在我面临列数的问题..我的 gridview xml 是,

<GridView
android:id="@+id/gv_gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:choiceMode="multipleChoice"
android:stretchMode="columnWidth"
android:gravity="center"
android:columnWidth="179dp">
</GridView>

我的网格项目布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="179dp"
android:layout_height="131dp"
android:padding="1dp" >

<ImageView
android:id="@+id/iv_thumbnail"
android:contentDescription="@string/iv_content_description"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />

<TextView
android:id="@+id/tv_folder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentBottom="true"
android:text="@string/tv_folder"
android:padding="12dp"
android:textColor="@color/white"
android:background="@color/transparent_black"/>

</RelativeLayout>

当然是根据设备宽度动态维护列,但不同设备的列间距不同..我该如何克服这个问题?

最佳答案

要均匀分布大小,请不要为每个网格项目使用固定大小。

设置宽度为wrap_content,也可以指定列数

关于android - 自动调整android中gridview中单元格的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26176705/

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