ScrollView嵌套GridView或ListView,由于这两款控件都自带滚动条,当他们碰到一起的时候便会出问题,即GridView会显示不全。

解决办法:自定义一个GridView控件

package cn.com.gxlu.frame.impl;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView; public class MyGrideView extends GridView { public MyGrideView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} public MyGrideView(Context context, AttributeSet attrs) {
super(context, attrs);
} public MyGrideView(Context context) {
super(context);
} @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, expandSpec);
}
}
该自定义控件只是重写了GridView的onMeasure方法,使其不会出现滚动条,ScrollView嵌套ListView也是同样的道理,不再赘述。 XML布局代码
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dddddd" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout> <cn.com.gxlu.frame.impl.MyGrideView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="35dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:horizontalSpacing="1dip"
android:numColumns="3"
android:verticalSpacing="1dip" >
</cn.com.gxlu.frame.impl.MyGrideView>
</LinearLayout> </ScrollView>

 

scorllview嵌套gridview和listview的兼容问题的更多相关文章

  1. ScrollView下嵌套GridView或ListView默认不在顶部的解决方法

    自定义ScrollView重写下面的方法 /* ScrollView下嵌套GridView或ListView默认不在顶部的解决方法*/ @Override protected int computeS ...

  2. ScrollView中嵌套GridView,ListView只显示一行的解决办法

    转载:http://blog.csdn.net/luohai859/article/details/39347583 关于为什么只显示一行,个人理解是:如果单独使用GridView和ListView, ...

  3. ScrollView中嵌套GridView,Listview的办法

    按照android的标准,ScrollView中是不能嵌套具有滑动特性的View的,但是有时如果设计真的有这样做的需要,或者为了更方便简单的实现外观(比如在外在的大布局需要有滑动的特性,并且内部有类似 ...

  4. Android 嵌套GridView,ListView只显示一行的解决办法

    重写ListView.GridView即可: public class MyListView extends ListView { public MyListView(Context context) ...

  5. 在SrollView中嵌套GridView或ListView(转)

    原文链接:http://blog.csdn.net/gaojinshan/article/details/17055511 我想在同一个界面中,使用两个GridView,两个GridView一起上下滚 ...

  6. android ScrollView中嵌套GridView,ListView只显示一行的解决办法

    http://blog.csdn.net/young0325/article/details/9831587

  7. ListView嵌套GridView使用详解及注意事项

    ListView嵌套GridView即ListView的每个Item中都包含一个GridView:需要注意的是由于ListView和GridView都是可滑动的控件. 所以需要自定义GridView, ...

  8. android 之 ListView 里面嵌套 GridView 遇到的问题及其解决方法。

    我们直接入主题.所有问题例子请参照下图 1,怎样使图片具有点击事件? 答: 解决方法: 在你的BaseAdapter里面不要设置下面这三个东西,然后再设置GridView的onItemClick. g ...

  9. android listView嵌套gridview的使用心得

    在开发的过程中可能需要用到listview嵌套gridview的场景,但是在Android中, 不能在一个拥有Scrollbar的组件中嵌入另一个拥有Scrollbar的组件,因为这不科学,会混淆滑动 ...

随机推荐

  1. 【codeforces 500D】New Year Santa Network

    [题目链接]:http://codeforces.com/problemset/problem/500/D [题意] 有n个节点构成一棵树; 让你随机地选取3个不同的点a,b,c; 然后计算dis(a ...

  2. 计算机基础(day02)

    目录 什么是编程? 计算机的组成 CPU(大脑) 控制器 运算器 存储器 主存 外存 IO设备 input设备(输入设备) output设备(输出设备) 多核cpu 32位和64位 机械硬盘工作原理 ...

  3. Django项目:CRM(客户关系管理系统)--76--66PerfectCRM实现CRM课程作业排名

    # classtop_urls.py # ————————64PerfectCRM实现CRM课程排名详情———————— from django.conf.urls import url from b ...

  4. 深入浅出 Java Concurrency (7): 锁机制 part 2 AQS[转]

    在理解J.U.C原理以及锁机制之前,我们来介绍J.U.C框架最核心也是最复杂的一个基础类:java.util.concurrent.locks.AbstractQueuedSynchronizer. ...

  5. Ceisum官方教程3 -- 空间数据可视化

    原文地址:https://cesiumjs.org/tutorials/Visualizing-Spatial-Data/ 这篇教程教你如何使用Cesium的Entity API去绘制空间数据,如点, ...

  6. vue elementui点击表格当前行radio单选选中

    官方文档:https://element.eleme.cn/#/zh-CN/component/radio 参考:https://www.cnblogs.com/steamed-twisted-rol ...

  7. 跟我一起做一个vue的小项目(八)

    接下来我们进行的是城市选择页面的路由配置 添加city.vue,使其点击城市,然后跳转到city页面 //router.js import Vue from 'vue' import Router f ...

  8. Django项目:CRM(客户关系管理系统)--23--15PerfectCRM实现King_admin多条件过滤

    登陆密码设置参考 http://www.cnblogs.com/ujq3/p/8553784.html list_filter = ('source','consultant','consult_co ...

  9. php用mysql方式连接数据库出现Deprecated报错

    以上是用php5.5 连接mysql数据库时报的错. 于是我用php5.4 连接正常没有报错. 这与mysql版本无关系,php 5.x版本,如5.2.5.3.5.4.5.5,怕跟不上时代,新的服务器 ...

  10. vim 查找及替换

    #全文(%)查找(s)行首2个空格开头(/^ ), 替换(g)为无即删掉(//) :%s/^ //g #全文查找每行尾的2个空格,删除 :%s/ $//g