listview高度设为wrap_content和match_parent

本文讨论了ListView设置高度为wrap_content时出现的问题:在初次加载时所有可见item的getview会被调用两次的现象。
listview高度设为wrap_content,第一次所有可见的item的getview会走两遍。
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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/main" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <!-- 连接区域 --> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="WiFi ADB 连接" android:textSize="18sp" android:textStyle="bold" android:layout_marginBottom="8dp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_marginBottom="8dp"> <EditText android:id="@+id/etIpAddress" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3" android:hint="设备IP地址" android:inputType="number"/> <EditText android:id="@+id/etPort" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:hint="端口" android:inputType="number" android:text="5555"/> </LinearLayout> <Button android:id="@+id/btnConnect" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="连接设备"/> <Button android:id="@+id/btnDisconnect" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="断开连接" android:visibility="gone"/> <TextView android:id="@+id/tvStatus" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="未连接设备" android:textStyle="italic" android:layout_marginVertical="8dp"/> <!-- 命令区域 --> <TextView android:id="@+id/tvCommand" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="AppOps 权限管理" android:textSize="18sp" android:textStyle="bold" android:layout_marginTop="16dp" android:layout_marginBottom="8dp"/> <LinearLayout android:id="@+id/groupCommand" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:visibility="gone"> <EditText android:id="@+id/etPackageName" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="应用包名" android:layout_marginBottom="8dp"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="选择权限操作" android:textStyle="bold"/> <Spinner android:id="@+id/spinnerCommonOps" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="8dp"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <CheckBox android:id="@+id/cbCustomOp" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="自定义权限操作" android:layout_gravity="center_vertical"/> </LinearLayout> <EditText android:id="@+id/etCustomOp" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="例如: RUN_IN_BACKGROUND" android:layout_marginBottom="8dp" android:enabled="false"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="设置权限模式" android:textStyle="bold"/> <Spinner android:id="@+id/spinnerMode" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="16dp"/> <Button android:id="@+id/btnExecute" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="执行命令"/> </LinearLayout> <!-- 结果区域 --> <TextView android:id="@+id/tvResult" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="" android:layout_marginTop="8dp"/> <ProgressBar android:id="@+id/progressBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:indeterminate="true" android:visibility="gone" android:layout_marginTop="16dp"/> </androidx.constraintlayout.widget.ConstraintLayout> 修复代码
10-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值