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. 深入浅出 Java Concurrency (8): 锁机制 part 3[转]

    接上篇,这篇从Lock.lock/unlock开始.特别说明在没有特殊情况下所有程序.API.文档都是基于JDK 6.0的. public void java.util.concurrent.lock ...

  2. C++标准输入问题

    1.读取数据量不定的输入数据 e.g. #include <iostream> using namespace std; void main() { ,val=; while(cin> ...

  3. MyBatis配置文件(九)--mappers映射器

    映射器是MyBatis中最复杂.最核心的组件,本文先介绍映射器的引入方法,其他的在我日后会再做分析和总结. 之前的文章中有提到过,映射器是由一个接口和一个XML配置文件组成,XML文件中需要定义一个命 ...

  4. jsonp 请求报Uncaught SyntaxError: Unexpected token :

    $(document).ready(function() { jQuery.ajax({ type: 'GET', url: 'http://wncrunners.com/admin/colors.j ...

  5. day18-事务与连接池 7.事务隔离级别总结

  6. JQuery学习:事件绑定&入口函数&样式控制

    1.基础语法学习: 1.事件绑定 2.入口函数 3.样式控制 <!DOCTYPE html> <html lang="en"> <head> & ...

  7. 关于dex 64K 引用限制

    1.官方文档 https://developer.android.com/studio/build/multidex 主要内容: 什么是64K限制 编码时如何避免64K 限制 拆分dex避免64K 限 ...

  8. Python中的一些模块用法

    python中os模块用法 python之模块之shutil模块 -------------------------------os模块-------------------------------- ...

  9. SSM3-SVN的安装和搭建环境

    1.安装svn 2.创建仓库 3.设置用户 . 4.eclipse和svn的集成 eclipse里安装SVN插件,一般来说,有两种方式: 直接下载SVN插件,将其解压到eclipse的对应目录里 使用 ...

  10. Appium_Python_Client介绍

    一.Appium_Python_Client介绍 Appium的实用方法都藏在Client的源码里,对于driver和webelement实例,均有对应的元素查找方法(webelement查找的是下面 ...