仿一号店APP商品分类效果开发Android版本

昨天我们一起学习了一下一号店(IOS版本)(仿一号店APP商品分类效果开发IOS)商品分类效果编写今天我们一起来看一下Android版本上面的实现。其实我们的实现的具体思路差不多。总体先搞定一级分类,然后二级我们这边使用GridView布局。然后点击一级分类的每一项的时候,动态显示以及隐藏相关的二级分类数据。现在我们来看一下实现的效果.

然后这边还有一点需要介绍的是ViewGrounp的一个动画android:animateLayoutchanges属性。这个属性设置这样就自动地按照默认方式来对要移除或添加的View,还有Group中的其他View进行动画。

下面一起来看一下代码实现.

(一)布局文件:

<span style="font-size:18px;"><?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" >

    <include layout="@layout/top_bar_one_layout" />

    <FrameLayout
        android:id="@+id/frame_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ScrollView
            android:scrollbars="none"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

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

                <LinearLayout
                    android:id="@+id/line_1"
                    android:layout_width="match_parent"
                    android:layout_height="108dip"
                    android:orientation="horizontal" >

                    <LinearLayout
                        android:id="@+id/linear_1"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_1"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:layout_marginBottom="7dip"
                            android:text="类别" />
                    </LinearLayout>

                    <include layout="@layout/line_option_vertical_category_layout" />

                    <LinearLayout
                        android:id="@+id/linear_2"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_2"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_2"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="7dip"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>

                    <include layout="@layout/line_option_vertical_category_layout" />

                    <LinearLayout
                        android:id="@+id/linear_3"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_3"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_3"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="7dip"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:animateLayoutChanges="false"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include
                        layout="@layout/line_option_category_layout" />

                    <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_1"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                   <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_2"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_3"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                    <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_3"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <include
                    android:id="@+id/hide_divider_1"
                    layout="@layout/line_option_category_layout" />

                <LinearLayout
                    android:id="@+id/line_2"
                    android:layout_width="match_parent"
                    android:layout_height="108dip"
                    android:orientation="horizontal" >

                    <LinearLayout
                        android:id="@+id/linear_4"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_4"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_4"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="7dip"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>

                    <include layout="@layout/line_option_vertical_category_layout" />

                    <LinearLayout
                        android:id="@+id/linear_5"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_5"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_5"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="7dip"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>

                    <include layout="@layout/line_option_vertical_category_layout" />

                    <LinearLayout
                        android:id="@+id/linear_6"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_6"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_6"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="7dip"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                    <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_4"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                    <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_5"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_6"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                    <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_6"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <include
                    android:id="@+id/hide_divider_2"
                     layout="@layout/line_option_category_layout" />

                <LinearLayout
                    android:id="@+id/line_3"
                    android:layout_width="match_parent"
                    android:layout_height="108dip"
                    android:orientation="horizontal" >

                    <LinearLayout
                        android:id="@+id/linear_7"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_7"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_margin="12dip"
                            android:layout_weight="1"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_7"
                            android:layout_width="match_parent"
                            android:layout_marginBottom="7dip"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>

                    <include layout="@layout/line_option_vertical_category_layout" />

                    <LinearLayout
                        android:id="@+id/linear_8"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_8"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_8"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="7dip"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>

                    <include layout="@layout/line_option_vertical_category_layout" />

                    <LinearLayout
                        android:id="@+id/linear_9"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_9"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_9"
                            android:layout_width="match_parent"
                            android:layout_marginBottom="7dip"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_7"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                    <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_7"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_8"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                   <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_8"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_9"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                    <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_9"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <include
                    android:id="@+id/hide_divider_3"
                    layout="@layout/line_option_category_layout" />

                <LinearLayout
                    android:id="@+id/line_4"
                    android:layout_width="match_parent"
                    android:layout_height="108dip"
                    android:orientation="horizontal" >

                    <LinearLayout
                        android:id="@+id/linear_10"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_10"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_10"
                            android:layout_width="match_parent"
                            android:layout_marginBottom="7dip"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>

                    <include layout="@layout/line_option_vertical_category_layout" />

                    <LinearLayout
                        android:id="@+id/linear_11"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_11"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                            android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_11"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:gravity="center"
                            android:layout_marginBottom="7dip"
                            android:text="类别" />
                    </LinearLayout>

                    <include layout="@layout/line_option_vertical_category_layout" />

                    <LinearLayout
                        android:id="@+id/linear_12"
                        android:layout_width="0dip"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:orientation="vertical" >

                        <ImageView
                            android:id="@+id/iv_12"
                            android:layout_width="match_parent"
                            android:layout_height="0dip"
                           android:layout_marginTop="12dip"
                            android:layout_marginLeft="12dip"
                            android:layout_marginRight="12dip"
                            android:layout_marginBottom="5dip"
                            android:layout_weight="1"
                            android:src="@drawable/ic_launcher" />

                        <TextView
                            android:id="@+id/tv_12"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="7dip"
                            android:gravity="center"
                            android:text="类别" />
                    </LinearLayout>
                </LinearLayout>

                <include
                    android:id="@+id/hide_divider_4"
                    layout="@layout/line_option_category_layout" />

                <LinearLayout
                    android:id="@+id/hide_10"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                   <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_10"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_11"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                    <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_11"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/hide_12"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:visibility="gone" >

                    <include layout="@layout/line_option_category_layout" />

                    <com.zttmall.widget.MyGridView
                        android:id="@+id/gv_12"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="#66cccccc"
                        android:listSelector="@color/transparent"
                        android:numColumns="3" >
                    </com.zttmall.widget.MyGridView>
                </LinearLayout>
            </LinearLayout>
        </ScrollView>
    </FrameLayout>

    <FrameLayout
        android:id="@+id/prompt_framelayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:visibility="gone" >

        <include layout="@layout/loading" />

        <include layout="@layout/empty" />

        <include layout="@layout/error" />
    </FrameLayout>

</LinearLayout></span>

(二)解决GridView与ScrollView的冲突问题

package com.zttmall.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

public class CustomGridView extends GridView {
	public CustomGridView(Context context) {
		super(context);
	}

	public CustomGridView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

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

	@Override
	public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
				MeasureSpec.AT_MOST);
		super.onMeasure(widthMeasureSpec, expandSpec);
	}
}

(三).具体实现代码如下:

package com.zttmall.fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import tv.pps.modules.imagelogic.ImageLogic;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.zttmall.BaseFragment;
import com.zttmall.ZTTMallApplication;
import com.zttmall.adapter.SubCategoryAdapter;
import com.zttmall.common.DefineView;
import com.zttmall.common.DeliverConsts;
import com.zttmall.common.RequestURL;
import com.zttmall.listlogic.ListFetcher;
import com.zttmall.listlogic.ListSimpleParse;
import com.zttmall.model.category.CategoryModel;
import com.zttmall.model.category.ShowCategoryModel;
import com.zttmall.model.category.SubCategoryModel;
import com.zttmall.ui.ClassifyThreeCategoryActivity;
import com.zttmall.ui.R;
import com.zttmall.utils.Log;

/**
 * 商品分类功能
 *
 * @author jiangqq
 *
 */
public class ClassifyFragment extends BaseFragment implements DefineView {
	private View mView;
	private TextView tab_bar_title_one;
	private ShowCategoryModel model;

	private FrameLayout frame_content;
	private FrameLayout prompt_framelayout;
	private LinearLayout loading;
	private LinearLayout empty;
	private LinearLayout error;

	String descString;
	private ListFetcher mListWorker;
	private HashMap<String, String> requestMap;

	private SubCategoryAdapter mSubCategoryAdapter;
	ImageLogic mImageLogic;
	private List<LinearLayout> linearList = new ArrayList<LinearLayout>();
	private List<ImageView> ivList = new ArrayList<ImageView>();
	private List<TextView> tvList = new ArrayList<TextView>();
	private List<LinearLayout> hideList = new ArrayList<LinearLayout>();
	private List<GridView> gvList = new ArrayList<GridView>();

	private Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			if (msg.what == ListFetcher.LIST_OK) {
				getDataOk();
			} else if (msg.what == ListFetcher.LIST_ERROR) {
				getDataError();
			}

		};
	};

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (mView == null) {
			mView = inflater.inflate(R.layout.classify_fragment_layout,
					container, false);
			initView();
			initValidata();
			initListener();
			bindData();
		}
		return mView;
	}

	@Override
	public void initView() {
		tab_bar_title_one = (TextView) mView
				.findViewById(R.id.tab_bar_title_one);
		tab_bar_title_one.setText(R.string.string_classify_name);
		frame_content = (FrameLayout) mView.findViewById(R.id.frame_content);
		prompt_framelayout = (FrameLayout) mView
				.findViewById(R.id.prompt_framelayout);
		loading = (LinearLayout) mView.findViewById(R.id.loading);
		empty = (LinearLayout) mView.findViewById(R.id.empty);
		error = (LinearLayout) mView.findViewById(R.id.error);

		initViewList();

	}

	public void initViewList() {

		/*
		 * line1 = (LinearLayout) mView.findViewById(R.id.line_1); line2 =
		 * (LinearLayout) mView.findViewById(R.id.line_2); line3 =
		 * (LinearLayout) mView.findViewById(R.id.line_3); line4 =
		 * (LinearLayout) mView.findViewById(R.id.line_4);
		 */

		linearList.add((LinearLayout) mView.findViewById(R.id.linear_1));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_2));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_3));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_4));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_5));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_6));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_7));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_8));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_9));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_10));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_11));
		linearList.add((LinearLayout) mView.findViewById(R.id.linear_12));

		ivList.add((ImageView) mView.findViewById(R.id.iv_1));
		ivList.add((ImageView) mView.findViewById(R.id.iv_2));
		ivList.add((ImageView) mView.findViewById(R.id.iv_3));
		ivList.add((ImageView) mView.findViewById(R.id.iv_4));
		ivList.add((ImageView) mView.findViewById(R.id.iv_5));
		ivList.add((ImageView) mView.findViewById(R.id.iv_6));
		ivList.add((ImageView) mView.findViewById(R.id.iv_7));
		ivList.add((ImageView) mView.findViewById(R.id.iv_8));
		ivList.add((ImageView) mView.findViewById(R.id.iv_9));
		ivList.add((ImageView) mView.findViewById(R.id.iv_10));
		ivList.add((ImageView) mView.findViewById(R.id.iv_11));
		ivList.add((ImageView) mView.findViewById(R.id.iv_12));

		tvList.add((TextView) mView.findViewById(R.id.tv_1));
		tvList.add((TextView) mView.findViewById(R.id.tv_2));
		tvList.add((TextView) mView.findViewById(R.id.tv_3));
		tvList.add((TextView) mView.findViewById(R.id.tv_4));
		tvList.add((TextView) mView.findViewById(R.id.tv_5));
		tvList.add((TextView) mView.findViewById(R.id.tv_6));
		tvList.add((TextView) mView.findViewById(R.id.tv_7));
		tvList.add((TextView) mView.findViewById(R.id.tv_8));
		tvList.add((TextView) mView.findViewById(R.id.tv_9));
		tvList.add((TextView) mView.findViewById(R.id.tv_10));
		tvList.add((TextView) mView.findViewById(R.id.tv_11));
		tvList.add((TextView) mView.findViewById(R.id.tv_12));

		hideList.add((LinearLayout) mView.findViewById(R.id.hide_1));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_2));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_3));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_4));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_5));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_6));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_7));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_8));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_9));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_10));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_11));
		hideList.add((LinearLayout) mView.findViewById(R.id.hide_12));

		gvList.add((GridView) mView.findViewById(R.id.gv_1));
		gvList.add((GridView) mView.findViewById(R.id.gv_2));
		gvList.add((GridView) mView.findViewById(R.id.gv_3));
		gvList.add((GridView) mView.findViewById(R.id.gv_4));
		gvList.add((GridView) mView.findViewById(R.id.gv_5));
		gvList.add((GridView) mView.findViewById(R.id.gv_6));
		gvList.add((GridView) mView.findViewById(R.id.gv_7));
		gvList.add((GridView) mView.findViewById(R.id.gv_8));
		gvList.add((GridView) mView.findViewById(R.id.gv_9));
		gvList.add((GridView) mView.findViewById(R.id.gv_10));
		gvList.add((GridView) mView.findViewById(R.id.gv_11));
		gvList.add((GridView) mView.findViewById(R.id.gv_12));
	}

	@Override
	public void initValidata() {
		// TODO Auto-generated method stub
		mImageLogic = ImageLogic.create(getActivity());
		mImageLogic.configBitmapMaxHeight(120);
		mImageLogic.configBitmapMaxWidth(120);

		mListWorker = new ListFetcher(getActivity(),
				ListSimpleParse.DEFAULT_JSON_CATEGORY, mHandler);
		mListWorker.loadJsonDataList(RequestURL.CATEGORY_URL);

		mSubCategoryAdapter = new SubCategoryAdapter(getActivity());

		frame_content.setVisibility(View.GONE);
		prompt_framelayout.setVisibility(View.VISIBLE);
		loading.setVisibility(View.VISIBLE);
		empty.setVisibility(View.GONE);
		error.setVisibility(View.GONE);
	}

	@Override
	public void initListener() {
		// TODO Auto-generated method stub
		error.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mListWorker.loadJsonDataList(RequestURL.CATEGORY_URL);
				frame_content.setVisibility(View.GONE);
				prompt_framelayout.setVisibility(View.VISIBLE);
				loading.setVisibility(View.VISIBLE);
				empty.setVisibility(View.GONE);
				error.setVisibility(View.GONE);
			}
		});
		for (int i = 0; i < linearList.size(); i++) {
			linearList.get(i).setOnClickListener(
					new MyCustomerOnclickListener());
		}
	}

	@Override
	public void bindData() {
		// TODO Auto-generated method stub

	}

	@Override
	public void getPageData() {
		// TODO Auto-generated method stub

	}

	@Override
	public void getDataOk() {
		// TODO Auto-generated method stub
		HashMap<String, Object> tempMap = ZTTMallApplication.getInstance()
				.getTempMap();
		model = (ShowCategoryModel) tempMap
				.get(DeliverConsts.KEY_CATEGORY_MODEL);
		if (model != null && model.getCode().equals("1")
				&& "SUCCESS".equals(model.getMsg())) {
			if (model.getData() != null && model.getData().size() > 0) {
				showData(model);
				frame_content.setVisibility(View.VISIBLE);
				prompt_framelayout.setVisibility(View.GONE);
				loading.setVisibility(View.GONE);
				empty.setVisibility(View.GONE);
				error.setVisibility(View.GONE);
			} else {
				frame_content.setVisibility(View.GONE);
				prompt_framelayout.setVisibility(View.VISIBLE);
				loading.setVisibility(View.GONE);
				empty.setVisibility(View.VISIBLE);
				error.setVisibility(View.GONE);
			}
		} else {
			frame_content.setVisibility(View.GONE);
			prompt_framelayout.setVisibility(View.VISIBLE);
			loading.setVisibility(View.GONE);
			empty.setVisibility(View.GONE);
			error.setVisibility(View.VISIBLE);
		}
	}

	@Override
	public void getDataError() {
		// TODO Auto-generated method stub

	}

	@Override
	public void getDataRefresh() {
		// TODO Auto-generated method stub

	}

	class MyCustomerOnclickListener implements OnClickListener {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.linear_1:
				showOrHide(0, model.getData().get(0).getSub_category());
				break;
			case R.id.linear_2:
				showOrHide(1, model.getData().get(1).getSub_category());
				break;
			case R.id.linear_3:
				showOrHide(2, model.getData().get(2).getSub_category());
				break;
			case R.id.linear_4:
				showOrHide(3, model.getData().get(3).getSub_category());
				break;
			case R.id.linear_5:
				showOrHide(4, model.getData().get(4).getSub_category());
				break;
			case R.id.linear_6:
				showOrHide(5, model.getData().get(5).getSub_category());
				break;
			case R.id.linear_7:
				showOrHide(6, model.getData().get(6).getSub_category());
				break;
			case R.id.linear_8:
				showOrHide(7, model.getData().get(7).getSub_category());
				break;
			case R.id.linear_9:
				showOrHide(8, model.getData().get(8).getSub_category());
				break;
			case R.id.linear_10:
				showOrHide(9, model.getData().get(9).getSub_category());
				break;
			case R.id.linear_11:
				showOrHide(10, model.getData().get(10).getSub_category());
				break;
			case R.id.linear_12:
				showOrHide(11, model.getData().get(11).getSub_category());
				break;
			}
		}

		void showOrHide(final int i, final List<SubCategoryModel> list) {
			if (list != null && list.size() > 0) {
				mSubCategoryAdapter.setmList(list);
				gvList.get(i).setAdapter(mSubCategoryAdapter);

				descString = model.getData().get(i).getDesc();
				mSubCategoryAdapter.notifyDataSetChanged();

				for (int j = 0; j < hideList.size(); j++) {
					if (j != i) {
						hideList.get(j).setVisibility(View.GONE);
					} else {
						if (hideList.get(i).getVisibility() == View.VISIBLE) {
							hideList.get(i).setVisibility(View.GONE);
						} else {
							hideList.get(i).setVisibility(View.VISIBLE);
							gvList.get(i).setOnItemClickListener(
									new OnItemClickListener() {

										@Override
										public void onItemClick(
												AdapterView<?> parent,
												View view, int position, long id) {
											// TODO Auto-generated method stub
											Intent _Intent = new Intent(
													getActivity(),
													ClassifyThreeCategoryActivity.class);
											_Intent.putExtra("title",
													descString);
											_Intent.putExtra(
													"content",
													JSON.toJSONString(list
															.get(position)
															.getThree_category()));
											startActivity(_Intent);
										}
									});
						}
					}
				}
			} else {
				List<SubCategoryModel> lists = new ArrayList<SubCategoryModel>();
				mSubCategoryAdapter.setmList(lists);
				mSubCategoryAdapter.notifyDataSetChanged();
			}

		}

	}

	void showData(ShowCategoryModel model) {
		List<CategoryModel> mLists = model.getData();
		int length = model.getData().size();
		for (int i = 0; i < model.getData().size(); i++) {
			tvList.get(i).setText(model.getData().get(i).getTitle());
			mImageLogic
					.display(ivList.get(i), model.getData().get(i).getIcon());
		}
		int temp = (length - 1) / 3 + 2;
		for (int i = length; i < linearList.size(); i++) {
			linearList.get(i).setVisibility(View.INVISIBLE);
		}
		if (linearList.size() > (temp - 1) * 3)
			for (int i = (temp - 1) * 3; i < linearList.size(); i++) {
				linearList.get(i).setVisibility(View.GONE);
			}

	}
}

相应的信息实体类(Model)就不贴了,直接上一篇博客就行了。

下面给一下测试的地址:http://img2.xxh.cc:8080/SalesWebTest/CategoryList

最后再说一下最近我自己在搞工作室,希望小编(如果小编看到这段觉得不妥,请帮我删掉这段,非常感谢!)以及路过的朋友们不要介意哦。优清科技工作室团队,主要承接Android/IOS,J2EE,.Net,PHP,移动建站,网站建设,微信系统项目开发。

时间: 2024-10-21 20:35:20

仿一号店APP商品分类效果开发Android版本的相关文章

仿一号店APP商品分类效果开发(Android和IOS)

好久没写博客了,一方面这段时间公司的事情项目比较多,另一方面自己也有准备成立自己的个人工作室,所以一直没顾得上去总结写一下技术博客,今天正好有点时间就来一篇吧. 这段时间一直在进行开发商城的APP(Android和IOS),也研究一下国内绝大多数的电商APP(例如:淘宝,京东,天猫,苏宁易购,顺丰优选等等),他们的商品分类其实大多数属于常见格调:列表-点击二级列表-具体三级分类列表.唯有看了一号店IOS端的APP,感觉还不错.一级格子分布,点击item,中间显示二级分类.然后我们团队决定仿照该效

【FastDev4Android框架开发】Android Design支持库TabLayout打造仿网易新闻Tab标签效果(三十七)

转载请标明出处: http://blog.csdn.net/developer_jiangqq/article/details/50158985 本文出自:[江清清的博客] (一).前言: 仿36Kr客户端开发过程中,因为他们网站上面的新闻文章分类比较多,所以我这边还是打算模仿网易新闻APP的主界面新闻标签Tab以及页面滑动效果来进行实现.要实现的顶部的Tab标签的效果有很多方法例如采用开源项目ViewPagerIndicator中的TabPageIndicator就可以实现.不过我们今天不讲V

Android基础入门教程——1.2.1 使用Eclipse + ADT + SDK开发Android APP

Android基础入门教程--1.2.1 使用Eclipse + ADT + SDK开发Android APP 标签(空格分隔): Android基础入门教程 1.前言 这里我们有两条路可以选,直接使用封装好的用于开发Android的ADT Bundle,或者自己进行配置 因为谷歌已经放弃了ADT的更新,官网上也取消的下载链接,这里提供谷歌放弃更新前最新版本的 ADT Bundle供大家下载! 2.直接使用打包好的Eclipse 32位版:adt-bundle-windows-x86-20140

Android 使用ContentProvider扫描手机中的图片,仿微信显示本地图片效果

首先我们先看第一个界面吧,使用将手机中的图片扫描出来,然后根据图片的所在的文件夹将其分类出来,并显示所在文件夹里面的一张图片和文件夹中图片个数,我们根据界面元素(文件夹名, 文件夹图片个数,文件夹中的一张图片)使用一个实体对象ImageBean来封装这三个属性 package com.example.imagescan; /** * GridView的每个item的数据对象 * * @author len * */ public class ImageBean{ /** * 文件夹的第一张图片路

Android耳机线控详解,蓝牙耳机按钮监听(仿酷狗线控效果)

转载请注明出处:http://blog.csdn.net/fengyuzhengfan/article/details/46461253 当耳机的媒体按键被单击后,Android系统会发出一个广播,该广播的携带者一个Action名为MEDIA_BUTTON的Intent.监听该广播便可以获取手机的耳机媒体按键的单击事件. 在Android中有个AudioManager类,该类会维护MEDIA_BUTTON广播的分发,所以要实现耳机按键监听需要向AudioManager注册一个用于接收耳机按键单击

Android基础新手教程——1.2.1 使用Eclipse + ADT + SDK开发Android APP

Android基础新手教程--1.2.1 使用Eclipse + ADT + SDK开发Android APP 标签(空格分隔): Android基础新手教程 1.前言 这里我们有两条路能够选,直接使用封装好的用于开发Android的ADT Bundle,或者自己进行配置 由于谷歌已经放弃了ADT的更新,官网上也取消的下载链接.这里提供谷歌放弃更新前最新版本号的 ADT Bundle供大家下载! 2.直接使用打包好的Eclipse 32位版:adt-bundle-windows-x86-2014

组件化封装开发Android App实战

详情请交流  QQ  709639943 01.组件化封装开发Android App实战 02.Kotlin系统入门与进阶 03.Node.js入门到企业Web开发中的应用 04.精通高级RxJava 2响应式编程思想 05.Java秒杀系统方案优化 高性能高并发实战 06.Java深入微服务原理改造房产销售平台 07.快速上手Linux 玩转典型应用 08.快速上手Ionic3 多平台开发企业级问答社区 09.Java Spring Security开发安全的REST服务 10.深入Java虚

Android项目实战(二十三):仿QQ设置App全局字体大小

原文:Android项目实战(二十三):仿QQ设置App全局字体大小 一.项目需求: 因为产品对象用于中老年人,所以产品设计添加了APP全局字体调整大小功能. 这里仿做QQ设置字体大小的功能. QQ实现的效果是,滚动下面的seekbar,当只有seekbar到达某一个刻度的时候,这时候上部分的效果展示部分会改变文字大小, 但是在拖动过程中字体不会改变.关闭此界面,就可以看到改变文字后app整体的实际文字大小效果了. ----------------------------------------

带领新手快速开发Android App开发视频课程 安卓快速入门教程

第1章 课程介绍与项目准备如果你从事Android开发,那你一定要学习一些开发技巧和掌握一些开发逻辑,而很不巧,我这里全部都有,最开始我们介绍一下我们这个应用的整体组织架构,通过对各个平台的api进行一个简单的分析,以及说明一下我们的RxVolley的网络框架使用教程,在本章中,我们将分析整个项目的大致架构,同时,我们有规范性的部署我们的项目... 第2章 工具类封装与首页引导页开发项目最讲究的前期架构搭建,我们把标准的Log和SharedPreferences进行封装,同时开发我们的首页和引导