android ListView layout_height属性值引发的问题

本文探讨了在Android应用开发中遇到的一个现象:当ListView的layout_height属性设置为matchparent时,嵌入的组件可能出现显示不完整或无法触发单击事件等问题。通过将布局高度设置为一个具体数值,如350dp,可以解决这些问题。这可能是Android平台的一个行为特性,而非bug。文章旨在分享这一经验,帮助开发者避免类似问题。

android ListView layout_height属性值引发的问题

问题: listview中的button 不能触发单击事件 或是 textview显示不完整,相关按钮不能单击等等

解决:将listview的layout_height属性值是不是设置成了match parent,如果是就将其改为一个合适的确定的数值(eg 350dp)

分析:最近在做的两个 android 项目都涉及到在listview中嵌入其他组件的,其中都出现了一个奇怪的现象:如果listview的设置宽度的属性(layout_height)设置为match parent时,listview中嵌入的 textview  checkebox button 等组件 均出现,文本显示内容不完整(有的可以显示内容有的不能显示内容) 按钮组件不能产生单击事件等情况。后来经过排查发现将listview的设置宽度的属性(layout_height)设置为一个合适的确定的数值(eg 350dp 能够匹配父控件)才不会出现以上情况。

不知这是不是android 平台的bug,本人接触android开发时间短,了解浅薄,贴出来希望知道的大虾们指点迷经。

<com.android.camera.ui.RotateLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:camera="http://schemas.android.com/apk/res/com.mediatek.camera0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:splitMotionEvents="false" > <com.android.camera.ui.MaxLinearLayout android:id="@+id/container" style="@style/htfSettingContainer" android:splitMotionEvents="false"> <!-- add by yanglh start --> <RelativeLayout android:id="@+id/setting_header" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFFFFF" android:layout_marginTop="30dp" > <ImageButton android:id="@+id/btn_back" android:layout_width="48dp" android:layout_height="48dp" android:layout_centerVertical="true" android:layout_alignParentStart="true" android:src="@drawable/htf_back_icon" android:background="@drawable/htf_round_back" android:contentDescription="back" /> <TextView android:id="@+id/tv_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginStart="50dp" android:text="@string/pref_camera_settings_category" android:textSize="18sp" android:textColor="#000000"/> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="#1AC0C0C0" /> <!-- add by yanglh end --> <TabHost android:id="@+id/tab_title" style="@style/SettingTabTitle"> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg_pressed" android:splitMotionEvents="false"> </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone" android:splitMotionEvents="false"> </FrameLayout> </TabHost> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"/> </com.android.camera.ui.MaxLinearLayout> </com.android.camera.ui.RotateLayout>在当前布局中添加属性使其可以上下滑动
最新发布
11-06
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto"> <androidx.appcompat.widget.LinearLayoutCompat android:layout_width="match_parent" android:orientation="vertical" android:layout_height="wrap_content"> <androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" app:title="" app:navigationIcon="@drawable/back"> </androidx.appcompat.widget.Toolbar> <ImageView android:layout_width="match_parent" android:layout_height="180dp" android:src="@mipmap/picture_8" android:scaleType="centerCrop"/> <androidx.appcompat.widget.LinearLayoutCompat android:layout_width="match_parent" android:layout_margin="10dp" android:orientation="vertical" android:layout_height="wrap_content"> </androidx.appcompat.widget.LinearLayoutCompat> <TextView android:layout_marginTop="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="泰山,又名岱山、岱宗、岱岳、东岳、泰岳,为五岳之一,有“五岳之首”、“五岳独尊”、“天下第一山”之称,被中外学者称为“中国的奥林匹斯山”,位于山东省中部,隶属于泰安市,绵亘于泰安、济南、淄博三市之间,总面积25000公顷,主峰玉皇顶海拔约1545米"/> </androidx.appcompat.widget.LinearLayoutCompat> </RelativeLayout>
06-24
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值