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
上一篇:c语言贪吃蛇详解-2.画出蛇


下一篇:C语言内存对齐详解(2)