GridView在ScrollView中實如今家更多

這個自己會有bug  應該在滑動監聽中做出判斷的android

<?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
相關文章
相關標籤/搜索