PullToRefreshScrollView嵌套两个GridView

做的android app中需要嵌入一个产品商城的功能。简单用com.handmark.pulltorefresh.library.PullToRefreshGridView显示一个产品列表完了。现在增加功能,需要把产品分成两个部分显示,一个是热卖产品,一个是所有产品。于是想到使com.handmark.pulltorefresh.library.PullToRefreshScrollView中嵌套两个GridView,GridView自定义,显示时计算条目的高度。
效果图:这里写图片描述

主要代码:
MyGridView.java:

public class MyGridView extends GridView {

    public MyGridView (Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    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) {
        // TODO Auto-generated method stub
        int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
        MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, expandSpec);
    }

}

布局文件product_home.xml主要代码:

<?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"
    android:background="@color/white"
    android:orientation="vertical" >

    <com.handmark.pulltorefresh.library.PullToRefreshScrollView
        android:id="@+id/ptr_scrollview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="none">     
        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            >
        <com.demo.view.MyGridView
            android:id="@+id/productlist"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"         
            android:numColumns="2" />

        <com.demo.view.MyGridView
            android:id="@+id/allproductlist"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"            
            android:numColumns="2" />  
        </LinearLayout>  </com.handmark.pulltorefresh.library.PullToRefreshScrollView>

</RelativeLayout>

MainActivity代码:

“`
package com.demo.activity;

public class MainActivity extends Activity {

private PullToRefreshScrollView ptr_scrollview;//
private MyGridView productGridView;// 
private MyGridView productAllGridView;// 

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.product_home);
    initView();
}

private void initView() {
    ptr_scrollview = (PullToRefreshScrollView) findViewById(R.id.ptr_scrollview);
ptr_scrollview.setMode(Mode.PULL_FROM_END);// 上拉刷新
    productGridView = (MyGridView) findViewById(R.id.productlist);
    productAllGridView = (MyGridView) findViewById(R.id.allproductlist);
    ptr_scrollview
            .setOnRefreshListener(new OnRefreshListener<ScrollView>() {
                @Override
                public void onRefresh(
                        PullToRefreshBase<ScrollView> refreshView) {
                    // TODO Auto-generated method stub
                }

            });

    productGridView
            .setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View arg1,
                        int pos, long id) {
                }
            });
    productAllGridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View arg1, int pos,
                long id) {
        }
    });
}

}

做个记录。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值