android - 如何在 Android 的 GridView 中设置子文本框的大小
问题描述
我的 Android 应用程序中有一个 GridView。我注意到,无论我如何指定各个 TextField 的高度/宽度,它们都不会反映在 GridView 的 TextField 中。
现在我正在寻找替代方法$android:columnWidth="90dp"
来创建特定宽度的 TextView。但是,如何在 GridView 中设置 TextViews 的高度?
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/park_cont"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:horizontalSpacing="5dp"
android:gravity="center"
android:numColumns="auto_fit"
android:padding="10dp"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".ParkingView"
tools:showIn="@layout/activity_parking_view" />
解决方案
您需要覆盖 的getView()
并ArrayAdapter
设置 的LayoutParam
高度View
。你需要按照以下几行做一些事情,
val adapter = object : ArrayAdapter<String>(
mContext,
android.R.layout.simple_list_item_1, flowers
) {
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val tvCell = super.getView(position, convertView, parent)
//Set the height of the view by settings it's layoutParams.height
tvCell.layoutParams.height = 1100
// Return the modified item
return tvCell
}
}
mGridView.adapter = adapter
推荐阅读
- php - NFC 标签打开的链接无法在 Android Chrome 上重定向
- javascript - 访问对象数组中信息的最佳实践。[.find() vs. .filter() vs. 创建引用对象]
- python - 查找大熊猫数据框的列发生变化的索引
- apache-kafka - kafka流+如何使状态存储中的条目异步过期
- android - 使用 AndroidX 的应用无法缩放文本
- python-3.x - Python陷入无限的While循环?
- assembly - 寄存器 a1 的地址超出范围错误
- c# - 将 .NET Core 2.2 迁移到 .NET Core 3.1 并继续引用 EF Core 2
- android - 颤振闪屏,里面有逻辑
- api - 尝试对 SSE 类型内容类型进行断言