ListView实现的商城列表页面

一、页面展示

页面展示

二、profile_browse_activity.xml布局代码:

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <!-- statr -->

    <include
        android:id="@+id/goodsgroupbuy_navbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/top_view" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent" >

            <ListView
                android:id="@+id/quality_list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="5dp"
                 />

            <FrameLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|right"
                android:layout_marginBottom="30dp"
                android:layout_marginRight="10dp" >

                <ImageView
                    android:id="@+id/good_detail_up"
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:background="@drawable/up_top_bg"
                    android:padding="12dp"
                    android:src="@drawable/up_top_icon" />
            </FrameLayout>
        </FrameLayout>
    </LinearLayout>
    <!-- end -->

</LinearLayout>  

预览:

列表布局

三、top_view.xml头部布局代码:

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="48dp" >

        <View
            android:layout_width="fill_parent"
            android:layout_height="20dp"
            android:background="#000000" />

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="48dp"
            android:background="@color/white" />

        <ImageView
            android:id="@+id/top_view_back"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="4dp"
            android:padding="10dp"
            android:src="@drawable/arrowleftcolor" />

        <TextView
            android:id="@+id/top_view_left"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:paddingLeft="15dp"
            android:paddingRight="5dp"
            android:text=""
            android:textColor="#ffffff"
            android:textSize="15sp"
            android:visibility="gone" />

        <TextView
            android:id="@+id/top_view_text"
            android:layout_width="230dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:ellipsize="end"
            android:gravity="center"
            android:singleLine="true"
            android:textColor="#85C226"
            android:textSize="18sp" />

        <ImageView
            android:id="@+id/top_right_button_iv"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_gravity="center_vertical|right"
            android:layout_marginRight="4dp"
            android:src="@drawable/home"
            android:visibility="gone" />

        <TextView
            android:id="@+id/top_right_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical|right"
            android:layout_marginRight="4dp"
            android:gravity="center"
            android:padding="10dp"
            android:text="@string/topview_message"
            android:textColor="#FFFFFF"
            android:textSize="15sp"
            android:visibility="gone" />
    </FrameLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#e4e4e4" >
    </LinearLayout>

</LinearLayout>  

四、list_no_more.xml布局代码:

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="false"
       android:background="#f7f7f7"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/packet_list_nomore"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:padding="10dp"
           android:background="#f7f7f7"
        android:text="亲,没有更多了"
        android:textColor="@color/filter_text_color"
        android:textSize="12dp" />

</LinearLayout>  

五、Profile_Browse_Activity代码:

public class Profile_Browse_Activity extends BaseActivity {  
    private TextView title;
    private ImageView back;
    private ImageView home;
    private ListView browseListView;
    BrowseListAdapter qualityListAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        setContentView(R.layout.profile_browse_activity);

        title = (TextView) findViewById(R.id.top_view_text);
        title.setText("浏览记录");

        home = (ImageView) findViewById(R.id.top_right_button_iv);
        home.setVisibility(View.VISIBLE);
        home.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();

            }
        });
        back = (ImageView) findViewById(R.id.top_view_back);
        back.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        browseListView = (ListView) findViewById(R.id.quality_list);
        View footview = LayoutInflater.from(this).inflate(
                R.layout.list_no_more, null);

        browseListView.addFooterView(footview);
        ImageView good_detail_up = (ImageView)           findViewById(R.id.good_detail_up);
        good_detail_up.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                if (browseListView != null) {
                    browseListView.setSelection(0);
                }
            }
        });
        qualityListAdapter = new BrowseListAdapter(this);
        browseListView.setAdapter(qualityListAdapter);
    }

    private class BrowseListAdapter extends BaseAdapter {
        private Context mContext;

        public BrowseListAdapter(Context context) {
            this.mContext = context;
        }
        public int getCount() {
                return texts.length;
        }

        public Object getItem(int position) {
            return null;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            // 优化ListView
            ItemViewCache viewCache;
            if (convertView == null) {
                convertView = LayoutInflater.from(mContext).inflate(
                        R.layout.profile_browse_list_item, null);
                viewCache = new ItemViewCache();
                viewCache.mTextView = (TextView) convertView
                        .findViewById(R.id.quality_name);
                viewCache.mPriceView = (TextView) convertView
                        .findViewById(R.id.quality_price);
                viewCache.mPhotoView = (ImageView) convertView
                        .findViewById(R.id.quality_photo);
                viewCache.mPrice2View = (TextView) convertView
                        .findViewById(R.id.quality_price_original);
                viewCache.mPrice2View.getPaint().setAntiAlias(true);
                viewCache.mPrice2View.getPaint().setFlags(
                        Paint.STRIKE_THRU_TEXT_FLAG);

                viewCache.mTextView.setText(texts[position]);
                viewCache.mPriceView.setText(texts1[position]);
                viewCache.mPhotoView.setImageResource(photo[position]);
                convertView.setTag(viewCache);
            } else {
                viewCache = (ItemViewCache) convertView.getTag();
            }

            return convertView;
        }
    }

    private static class ItemViewCache {
        public TextView mTextView;
        public TextView mPriceView;
        public ImageView mPhotoView;
        public TextView mPrice2View;

    }

    // 展示的文字
    private String[] texts = new String[] { "澳大利亚进口牛奶 德运全脂纯牛奶1L*10盒装整箱 澳洲鲜牛奶",
            "澳洲进口牛肉 家庭牛排组合套餐 肉眼牛仔骨西冷", "科尔沁黑椒菲力牛排(家庭装)300G", "越南红芒果700G",
            "筒骨500G", "乌鸡 3.2-3.5斤/只", "【良品铺子】芒果干 菲律宾水果干特产蜜饯果脯零食108g*3袋",
            "手撕牛肉条特产零食美味正宗138g多种口味" };
    private String[] texts1 = new String[] { "¥38.00", "¥24.00", "¥24.00",
            "¥24.00", "¥24.00", "¥24.00", "¥24.00", "¥24.00" };
    private int[] photo = new int[] { R.drawable.browse_photo1,
            R.drawable.browse_photo2, R.drawable.browse_photo3,
            R.drawable.browse_photo4, R.drawable.browse_photo5,
            R.drawable.browse_photo6, R.drawable.browse_photo7,
            R.drawable.browse_photo8 };

    @Override
    public void finish() {
        // TODO Auto-generated method stub
        super.finish();
    }

}

六、图片资源:

这里写图片描述这里写图片描述这里写图片描述这里写图片描述这里写图片描述这里写图片描述这里写图片描述这里写图片描述