GridView在ScrollView中实现在家更多

这个本身会有bug  应该在滑动监听中作出判断的

<?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">    <ScrollView        android:id="@+id/s"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:fillViewport="false"        android:scrollbars="none">         <LinearLayout             android:layout_width="match_parent"             android:layout_height="match_parent"             android:orientation="vertical">            <TextView                android:id="@+id/love"                android:layout_width="match_parent"                android:layout_height="100dp"                android:background="#fffccc"                android:text="caini xihuan " />             <com.maoyudun.alimamaproject.widget.MyGridView                 android:id="@+id/fourth_GridView"                 android:layout_width="match_parent"                 android:layout_height="match_parent"                 android:background="#f4f5f9"                 android:horizontalSpacing="10px"                 android:numColumns="2"                 android:verticalSpacing="10px" />             <LinearLayout                 android:id="@+id/loadmore"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:gravity="center"                 android:visibility="gone">                 <ProgressBar                     android:id="@+id/pb_progress"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center"                     android:indeterminateDrawable="@drawable/custom_progress" />                 <TextView                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_gravity="center_vertical"                     android:layout_marginLeft="5dp"                     android:text="正在加载..."                     android:textColor="@android:color/black"                     android:textSize="20dp"                     android:visibility="visible" />             </LinearLayout>        </LinearLayout>    </ScrollView></RelativeLayout>  
解决显示不全的问题自定义的GridView
public class MyGridView extends GridView{    public MyGridView(Context context) {        super(context);    }    public MyGridView(Context context, AttributeSet attrs) {        super(context, attrs);    }

public MyGridView(Context context, AttributeSet attrs,                      int defStyle) {        super(context, attrs, defStyle);    }

@Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,                MeasureSpec.AT_MOST);        super.onMeasure(widthMeasureSpec, expandSpec);    }}定义接口监听什么时候显示最后一条数据
public interface LoadMoreGridViewListener {    void loadMore(int position);}在adapter中调用接口回传数据
LoadMoreGridViewListener loadmore;public void onLoadMoreListener(LoadMoreGridViewListener load){    loadmore=load;}
/** * 判断滑动的位置 */if(position==mDatas.size()-1){    loadmore.loadMore(position);}在new adapater使用
void loadMore(int position);接口方法获取最后一个  
adapter.onLoadMoreListener(new LoadMoreGridViewListener() {    @Override    public void loadMore(int position) {        loadmore.animate().translationY(0).setDuration(300).setInterpolator(new AccelerateDecelerateInterpolator())                .setListener(new Animator.AnimatorListener() {                    @Override                    public void onAnimationStart(Animator animation) {                        loadmore.setVisibility(View.VISIBLE);                        handler.sendEmptyMessageDelayed(1,5000);

}

@Override                    public void onAnimationEnd(Animator animation) {

}

@Override                    public void onAnimationCancel(Animator animation) {

}

@Override                    public void onAnimationRepeat(Animator animation) {

}                });    }});
隐藏加载更多的时候直接GONE
时间: 2025-01-02 10:09:16

GridView在ScrollView中实现在家更多的相关文章

ScrollView中的ListView、GridView

介绍ScrollView中放ListView的文章着实不少,总结起来的话主要分两种 1.动态设置ListView的大小 2.重写ListView 本文目的是用最简单的方法实现我们想要的效果. 最简单方法就是重写ListVIew的onMeasure方法,请看下面的代码: public class ListViewForScrollView extends ListView { public ListViewForScrollView(Context context, AttributeSet at

Android学习之——如何将GridView内嵌在ScrollView中

最近在做一个项目,有一个需求是在ScrollView中内嵌一个GridView. 刚开始,我是以为能直接内嵌在里面: 1 <ScrollView 2 android:layout_width="match_parent" 3 android:layout_height="0dp" 4 android:layout_weight="5.5"> 5 <GridView 6 android:id="@+id/gridView

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

转载:http://blog.csdn.net/luohai859/article/details/39347583 关于为什么只显示一行,个人理解是:如果单独使用GridView和ListView,里面的内容是固定的,底层系统很容易计算出控件要占用的宽高,当外面嵌套一层ScrollView后,就能做上下或左右滑动,但能滑动多少系统不知道,这时就需要你给计算出一个滑动区域给ScrollView.而这个数值就是通过GridView和ListView中的内容总的宽高之和.有更精确的理解欢迎赐教.解决

ScrollView中嵌套GridView,Listview的办法

按照android的标准,ScrollView中是不能嵌套具有滑动特性的View的,但是有时如果设计真的有这样做的需要,或者为了更方便简单的实现外观(比如在外在的大布局需要有滑动的特性,并且内部有类似于List的UI结构,那么ListView + Adpater的方式来实现里面的效果就很方便,算是违规抄近道的一种方式吧),有时就会不得不采用这种怪异的组合方式. 先说下这种方式如果不做特殊处理时会出现的冲突和问题: 1,在SrollView中嵌套ListView,ListView的显示会有问题,只

ScrollView中嵌入ListView,GridView冲突的解决(让ListView全显示出来)

ScrollView中嵌入原生ListView或GridView,会出现ListView,GridView显示不全的问题. 解决方法:重新构造一个ListView或GridView,重写OnMeasure()方法: // ListView 1 import android.widget.ListView; 2 3 public class MyListView extends ListView{ 4 5 public MyListView(android.content.Context cont

关于 Android 中ScrollView中带有ListView 或者是Gridview的子视图的问题解决方案

问题如下描述: 关于 Android 中ScrollView中带有ListView 或者是Gridview的子视图的问题,在第一次加载的时候,会使得ScrollView 不在顶端.会往下移动,这个是因为其子视图抢占了焦点. 解决这样的问题,只要重写两个方法 : pasting 这样的话,第一次加载的时候就将ScrollView牢牢的锁在了第一.当用户交互的时候,就可以恢复正常.

解决ScrollView中listview、gridview的嵌套问题

一.listview public class ListViewForScrollView extends ListView { public ListViewForScrollView(Context context) {  super(context); } public ListViewForScrollView(Context context, AttributeSet attrs) {  super(context, attrs); } public ListViewForScroll

解决在ScrollView中套用ListView显示不正常

最近在设计Android程序时,因为需要在ScrollView中添加一个ListView列表来显示一些信息.刚开始并没有想太多,但添加进去后才发现ListView不论怎样定义都只能显示一行,显示效果很不正常. 后来在网上查了一下才知道,原因是ScrollView和ListView默认都带有滚动条,所以一起使用就会引起冲突.但因为程序中我必须要添加一个ListView,且不想取消外层的ScrollView(想保证用户在程序页面能够上下滑动来浏览更多内容),经过查询找到了解决此问题的方法. 下面记录

Android 设置ListView不可滚动 及在ScrollView中不可滚动的设置

http://m.blog.csdn.net/blog/yusewuhen/43706169 转载请注明出处: http://blog.csdn.net/androiddevelop/article/details/38815493 希望得到的效果是ListView不能滚动,但是最大的问题在与ListView Item还必有点击事件,如果不需要点击事件那就简单了,直接设置ListView.setEnable(false); 如果还需要点击事件,滚动与点击都是在ListView Touch处理机制