Android-onMeasure使用解决Scrollview嵌套listview冲突
来源:互联网 发布:g92多头螺纹编程实例 编辑:程序博客网 时间:2024/06/06 13:58
(一)冲突情况如图
解决冲突后:
(二)解决方法:自定义一个MyListView,使用onMeasure方法测量(设置)MyListview的宽和高
(三) 难点:
1、 onMeasure( int widthMeasureSpec,int heightMeasureSpec) 方法
自学中查资料看到很多博客中大神都是直接使用,
int a=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST);1.1 MeasureSpec: A MeasureSpec encapsulates the layout requirements passed from parent to child( 官方解 释)
1.2 makeMeasureSpec(size,mode):
参数size:是设置大小的,可以自己写入数值(比如200),
参数mode:是模式,系统提供了MeasureSpec.EXACTLY、MeasureSpec.AT_MOST、MeasureSpec.UNSPECIFIED三种模式
因为int a最大位数为32位,前两位用于表示模式的类型,后30位才是真正的用于表示size,所以使用Integer.MAX_VALUE>>2,表示size是最大的
代码:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"><com.example.xx.scroll_and_listview.MyListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/app_list"></com.example.xx.scroll_and_listview.MyListView> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点我"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点我"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点我"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点我"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点我"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点我"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="点我"/> </LinearLayout> </LinearLayout></ScrollView>
MyListView.java
public class MyListView extends ListView { public MyListView(Context context) { super(context); } public MyListView(Context context, AttributeSet attrs) { super(context, attrs); } public MyListView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int a=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE>>2,MeasureSpec.AT_MOST); int b=MeasureSpec.makeMeasureSpec(200,MeasureSpec.AT_MOST); super.onMeasure(b, a); }}
- Android-onMeasure使用解决Scrollview嵌套listview冲突
- 解决scrollView嵌套listview 冲突
- scrollview嵌套listView冲突解决
- 完美解决Android中,ScrollView嵌套ListView的冲突。
- android 解决ScrollView中嵌套ListView的冲突
- Android解决ScrollView嵌套ListView滑动冲突问题
- android ListView/GridView与ScrollView嵌套的滑动冲突解决
- android之ScrollView里嵌套ListView或GridView解决冲突
- Android中ScrollView和listView嵌套 滑动冲突解决
- Android ScrollView中嵌套ListView,滑动冲突问题的解决
- Android - ScrollView中嵌套ListView的冲突解决
- 完美解决Android中,ScrollView嵌套ListView的冲突。
- Android之解决scrollview嵌套listview的冲突
- Android ScrollView中嵌套ListView,滑动冲突问题的解决
- ScrollView嵌套使用ListView冲突的解决与分析
- 解决ScrollView嵌套ListView的冲突
- 解决scrollView嵌套listview的冲突问题
- ScrollView嵌套ListView冲突的解决
- Think in java笔记: Annotation
- 一个数组除了一个元素只出现一次,其他元素全都出现了三次,输出出现一次的元素
- FastDFS分布文件系统Java客户端使用
- 第八周--项目2-建立链串的算法库
- 阿里云数据库团队招聘
- Android-onMeasure使用解决Scrollview嵌套listview冲突
- C++的精髓——虚函数
- 欢迎使用CSDN-markdown编辑器
- 【Android】Android开发之常用的loading等待效果实现,仿微博等待动画。两种实现方式详解
- iOS 关于字体根据不同屏幕尺寸等比适配的问题
- EJB<一>
- spring 事务@Transactional注解位置
- Java第七章数组与枚举实验一(遍历与复制数组)
- jfastjson 常用类