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

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


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

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

      (一)布局文件:

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. <span style="font-size:18px;"><?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <include layout="@layout/top_bar_one_layout" />  
  8.   
  9.     <FrameLayout  
  10.         android:id="@+id/frame_content"  
  11.         android:layout_width="match_parent"  
  12.         android:layout_height="match_parent" >  
  13.   
  14.         <ScrollView  
  15.             android:scrollbars="none"  
  16.             android:layout_width="match_parent"  
  17.             android:layout_height="match_parent" >  
  18.   
  19.             <LinearLayout  
  20.                 android:layout_width="match_parent"  
  21.                 android:layout_height="match_parent"  
  22.                 android:animateLayoutChanges="true"  
  23.                 android:orientation="vertical" >  
  24.   
  25.                 <LinearLayout  
  26.                     android:id="@+id/line_1"  
  27.                     android:layout_width="match_parent"  
  28.                     android:layout_height="108dip"  
  29.                     android:orientation="horizontal" >  
  30.   
  31.                     <LinearLayout  
  32.                         android:id="@+id/linear_1"  
  33.                         android:layout_width="0dip"  
  34.                         android:layout_height="match_parent"  
  35.                         android:layout_weight="1"  
  36.                         android:orientation="vertical" >  
  37.   
  38.                         <ImageView  
  39.                             android:id="@+id/iv_1"  
  40.                             android:layout_width="match_parent"  
  41.                             android:layout_height="0dip"  
  42.                             android:layout_marginTop="12dip"  
  43.                             android:layout_marginLeft="12dip"  
  44.                             android:layout_marginRight="12dip"  
  45.                             android:layout_marginBottom="5dip"  
  46.                             android:layout_weight="1"  
  47.                             android:src="@drawable/ic_launcher" />  
  48.   
  49.                         <TextView  
  50.                             android:id="@+id/tv_1"  
  51.                             android:layout_width="match_parent"  
  52.                             android:layout_height="wrap_content"  
  53.                             android:gravity="center"  
  54.                             android:layout_marginBottom="7dip"  
  55.                             android:text="类别" />  
  56.                     </LinearLayout>  
  57.   
  58.                     <include layout="@layout/line_option_vertical_category_layout" />  
  59.   
  60.                     <LinearLayout  
  61.                         android:id="@+id/linear_2"  
  62.                         android:layout_width="0dip"  
  63.                         android:layout_height="match_parent"  
  64.                         android:layout_weight="1"  
  65.                         android:orientation="vertical" >  
  66.   
  67.                         <ImageView  
  68.                             android:id="@+id/iv_2"  
  69.                             android:layout_width="match_parent"  
  70.                             android:layout_height="0dip"  
  71.                             android:layout_marginTop="12dip"  
  72.                             android:layout_marginLeft="12dip"  
  73.                             android:layout_marginRight="12dip"  
  74.                             android:layout_marginBottom="5dip"  
  75.                             android:layout_weight="1"  
  76.                             android:src="@drawable/ic_launcher" />  
  77.   
  78.                         <TextView  
  79.                             android:id="@+id/tv_2"  
  80.                             android:layout_width="match_parent"  
  81.                             android:layout_height="wrap_content"  
  82.                             android:layout_marginBottom="7dip"  
  83.                             android:gravity="center"  
  84.                             android:text="类别" />  
  85.                     </LinearLayout>  
  86.   
  87.                     <include layout="@layout/line_option_vertical_category_layout" />  
  88.   
  89.                     <LinearLayout  
  90.                         android:id="@+id/linear_3"  
  91.                         android:layout_width="0dip"  
  92.                         android:layout_height="match_parent"  
  93.                         android:layout_weight="1"  
  94.                         android:orientation="vertical" >  
  95.   
  96.                         <ImageView  
  97.                             android:id="@+id/iv_3"  
  98.                             android:layout_width="match_parent"  
  99.                             android:layout_height="0dip"  
  100.                             android:layout_marginTop="12dip"  
  101.                             android:layout_marginLeft="12dip"  
  102.                             android:layout_marginRight="12dip"  
  103.                             android:layout_marginBottom="5dip"  
  104.                             android:layout_weight="1"  
  105.                             android:src="@drawable/ic_launcher" />  
  106.   
  107.                         <TextView  
  108.                             android:id="@+id/tv_3"  
  109.                             android:layout_width="match_parent"  
  110.                             android:layout_height="wrap_content"  
  111.                             android:layout_marginBottom="7dip"  
  112.                             android:gravity="center"  
  113.                             android:text="类别" />  
  114.                     </LinearLayout>  
  115.                 </LinearLayout>  
  116.   
  117.                 <LinearLayout  
  118.                     android:id="@+id/hide_1"  
  119.                     android:layout_width="match_parent"  
  120.                     android:layout_height="wrap_content"  
  121.                     android:animateLayoutChanges="false"  
  122.                     android:orientation="vertical"  
  123.                     android:visibility="gone" >  
  124.   
  125.                     <include  
  126.                         layout="@layout/line_option_category_layout" />  
  127.   
  128.                     <com.zttmall.widget.MyGridView  
  129.                         android:id="@+id/gv_1"  
  130.                         android:layout_width="match_parent"  
  131.                         android:layout_height="wrap_content"  
  132.                         android:background="#66cccccc"  
  133.                         android:listSelector="@color/transparent"  
  134.                         android:numColumns="3" >  
  135.                     </com.zttmall.widget.MyGridView>  
  136.                 </LinearLayout>  
  137.   
  138.                 <LinearLayout  
  139.                     android:id="@+id/hide_2"  
  140.                     android:layout_width="match_parent"  
  141.                     android:layout_height="wrap_content"  
  142.                     android:orientation="vertical"  
  143.                     android:visibility="gone" >  
  144.   
  145.                     <include layout="@layout/line_option_category_layout" />  
  146.   
  147.                    <com.zttmall.widget.MyGridView  
  148.                         android:id="@+id/gv_2"  
  149.                         android:layout_width="match_parent"  
  150.                         android:layout_height="wrap_content"  
  151.                         android:background="#66cccccc"  
  152.                         android:listSelector="@color/transparent"  
  153.                         android:numColumns="3" >  
  154.                     </com.zttmall.widget.MyGridView>  
  155.                 </LinearLayout>  
  156.   
  157.                 <LinearLayout  
  158.                     android:id="@+id/hide_3"  
  159.                     android:layout_width="match_parent"  
  160.                     android:layout_height="wrap_content"  
  161.                     android:orientation="vertical"  
  162.                     android:visibility="gone" >  
  163.   
  164.                     <include layout="@layout/line_option_category_layout" />  
  165.   
  166.                     <com.zttmall.widget.MyGridView  
  167.                         android:id="@+id/gv_3"  
  168.                         android:layout_width="match_parent"  
  169.                         android:layout_height="wrap_content"  
  170.                         android:background="#66cccccc"  
  171.                         android:listSelector="@color/transparent"  
  172.                         android:numColumns="3" >  
  173.                     </com.zttmall.widget.MyGridView>  
  174.                 </LinearLayout>  
  175.   
  176.                 <include   
  177.                     android:id="@+id/hide_divider_1"  
  178.                     layout="@layout/line_option_category_layout" />  
  179.   
  180.                 <LinearLayout  
  181.                     android:id="@+id/line_2"  
  182.                     android:layout_width="match_parent"  
  183.                     android:layout_height="108dip"  
  184.                     android:orientation="horizontal" >  
  185.   
  186.                     <LinearLayout  
  187.                         android:id="@+id/linear_4"  
  188.                         android:layout_width="0dip"  
  189.                         android:layout_height="match_parent"  
  190.                         android:layout_weight="1"  
  191.                         android:orientation="vertical" >  
  192.   
  193.                         <ImageView  
  194.                             android:id="@+id/iv_4"  
  195.                             android:layout_width="match_parent"  
  196.                             android:layout_height="0dip"  
  197.                             android:layout_marginTop="12dip"  
  198.                             android:layout_marginLeft="12dip"  
  199.                             android:layout_marginRight="12dip"  
  200.                             android:layout_marginBottom="5dip"  
  201.                             android:layout_weight="1"  
  202.                             android:src="@drawable/ic_launcher" />  
  203.   
  204.                         <TextView  
  205.                             android:id="@+id/tv_4"  
  206.                             android:layout_width="match_parent"  
  207.                             android:layout_height="wrap_content"  
  208.                             android:layout_marginBottom="7dip"  
  209.                             android:gravity="center"  
  210.                             android:text="类别" />  
  211.                     </LinearLayout>  
  212.   
  213.                     <include layout="@layout/line_option_vertical_category_layout" />  
  214.   
  215.                     <LinearLayout  
  216.                         android:id="@+id/linear_5"  
  217.                         android:layout_width="0dip"  
  218.                         android:layout_height="match_parent"  
  219.                         android:layout_weight="1"  
  220.                         android:orientation="vertical" >  
  221.   
  222.                         <ImageView  
  223.                             android:id="@+id/iv_5"  
  224.                             android:layout_width="match_parent"  
  225.                             android:layout_height="0dip"  
  226.                             android:layout_marginTop="12dip"  
  227.                             android:layout_marginLeft="12dip"  
  228.                             android:layout_marginRight="12dip"  
  229.                             android:layout_marginBottom="5dip"  
  230.                             android:layout_weight="1"  
  231.                             android:src="@drawable/ic_launcher" />  
  232.   
  233.                         <TextView  
  234.                             android:id="@+id/tv_5"  
  235.                             android:layout_width="match_parent"  
  236.                             android:layout_height="wrap_content"  
  237.                             android:layout_marginBottom="7dip"  
  238.                             android:gravity="center"  
  239.                             android:text="类别" />  
  240.                     </LinearLayout>  
  241.   
  242.                     <include layout="@layout/line_option_vertical_category_layout" />  
  243.   
  244.                     <LinearLayout  
  245.                         android:id="@+id/linear_6"  
  246.                         android:layout_width="0dip"  
  247.                         android:layout_height="match_parent"  
  248.                         android:layout_weight="1"  
  249.                         android:orientation="vertical" >  
  250.   
  251.                         <ImageView  
  252.                             android:id="@+id/iv_6"  
  253.                             android:layout_width="match_parent"  
  254.                             android:layout_height="0dip"  
  255.                             android:layout_marginTop="12dip"  
  256.                             android:layout_marginLeft="12dip"  
  257.                             android:layout_marginRight="12dip"  
  258.                             android:layout_marginBottom="5dip"  
  259.                             android:layout_weight="1"  
  260.                             android:src="@drawable/ic_launcher" />  
  261.   
  262.                         <TextView  
  263.                             android:id="@+id/tv_6"  
  264.                             android:layout_width="match_parent"  
  265.                             android:layout_height="wrap_content"  
  266.                             android:layout_marginBottom="7dip"  
  267.                             android:gravity="center"  
  268.                             android:text="类别" />  
  269.                     </LinearLayout>  
  270.                 </LinearLayout>  
  271.   
  272.                 <LinearLayout  
  273.                     android:id="@+id/hide_4"  
  274.                     android:layout_width="match_parent"  
  275.                     android:layout_height="wrap_content"  
  276.                     android:orientation="vertical"  
  277.                     android:visibility="gone" >  
  278.   
  279.                     <include layout="@layout/line_option_category_layout" />  
  280.   
  281.                     <com.zttmall.widget.MyGridView  
  282.                         android:id="@+id/gv_4"  
  283.                         android:layout_width="match_parent"  
  284.                         android:layout_height="wrap_content"  
  285.                         android:background="#66cccccc"  
  286.                         android:listSelector="@color/transparent"  
  287.                         android:numColumns="3" >  
  288.                     </com.zttmall.widget.MyGridView>  
  289.                 </LinearLayout>  
  290.   
  291.                 <LinearLayout  
  292.                     android:id="@+id/hide_5"  
  293.                     android:layout_width="match_parent"  
  294.                     android:layout_height="wrap_content"  
  295.                     android:orientation="vertical"  
  296.                     android:visibility="gone" >  
  297.   
  298.                     <include layout="@layout/line_option_category_layout" />  
  299.   
  300.                     <com.zttmall.widget.MyGridView  
  301.                         android:id="@+id/gv_5"  
  302.                         android:layout_width="match_parent"  
  303.                         android:layout_height="wrap_content"  
  304.                         android:background="#66cccccc"  
  305.                         android:listSelector="@color/transparent"  
  306.                         android:numColumns="3" >  
  307.                     </com.zttmall.widget.MyGridView>  
  308.                 </LinearLayout>  
  309.   
  310.                 <LinearLayout  
  311.                     android:id="@+id/hide_6"  
  312.                     android:layout_width="match_parent"  
  313.                     android:layout_height="wrap_content"  
  314.                     android:orientation="vertical"  
  315.                     android:visibility="gone" >  
  316.   
  317.                     <include layout="@layout/line_option_category_layout" />  
  318.   
  319.                     <com.zttmall.widget.MyGridView  
  320.                         android:id="@+id/gv_6"  
  321.                         android:layout_width="match_parent"  
  322.                         android:layout_height="wrap_content"  
  323.                         android:background="#66cccccc"  
  324.                         android:listSelector="@color/transparent"  
  325.                         android:numColumns="3" >  
  326.                     </com.zttmall.widget.MyGridView>  
  327.                 </LinearLayout>  
  328.   
  329.                 <include  
  330.                     android:id="@+id/hide_divider_2"  
  331.                      layout="@layout/line_option_category_layout" />  
  332.   
  333.                 <LinearLayout  
  334.                     android:id="@+id/line_3"  
  335.                     android:layout_width="match_parent"  
  336.                     android:layout_height="108dip"  
  337.                     android:orientation="horizontal" >  
  338.   
  339.                     <LinearLayout  
  340.                         android:id="@+id/linear_7"  
  341.                         android:layout_width="0dip"  
  342.                         android:layout_height="match_parent"  
  343.                         android:layout_weight="1"  
  344.                         android:orientation="vertical" >  
  345.   
  346.                         <ImageView  
  347.                             android:id="@+id/iv_7"  
  348.                             android:layout_width="match_parent"  
  349.                             android:layout_height="0dip"  
  350.                             android:layout_margin="12dip"  
  351.                             android:layout_weight="1"  
  352.                             android:layout_marginTop="12dip"  
  353.                             android:layout_marginLeft="12dip"  
  354.                             android:layout_marginRight="12dip"  
  355.                             android:layout_marginBottom="5dip"  
  356.                             android:src="@drawable/ic_launcher" />  
  357.   
  358.                         <TextView  
  359.                             android:id="@+id/tv_7"  
  360.                             android:layout_width="match_parent"  
  361.                             android:layout_marginBottom="7dip"  
  362.                             android:layout_height="wrap_content"  
  363.                             android:gravity="center"  
  364.                             android:text="类别" />  
  365.                     </LinearLayout>  
  366.   
  367.                     <include layout="@layout/line_option_vertical_category_layout" />  
  368.   
  369.                     <LinearLayout  
  370.                         android:id="@+id/linear_8"  
  371.                         android:layout_width="0dip"  
  372.                         android:layout_height="match_parent"  
  373.                         android:layout_weight="1"  
  374.                         android:orientation="vertical" >  
  375.   
  376.                         <ImageView  
  377.                             android:id="@+id/iv_8"  
  378.                             android:layout_width="match_parent"  
  379.                             android:layout_height="0dip"  
  380.                             android:layout_marginTop="12dip"  
  381.                             android:layout_marginLeft="12dip"  
  382.                             android:layout_marginRight="12dip"  
  383.                             android:layout_marginBottom="5dip"  
  384.                             android:layout_weight="1"  
  385.                             android:src="@drawable/ic_launcher" />  
  386.   
  387.                         <TextView  
  388.                             android:id="@+id/tv_8"  
  389.                             android:layout_width="match_parent"  
  390.                             android:layout_height="wrap_content"  
  391.                             android:layout_marginBottom="7dip"  
  392.                             android:gravity="center"  
  393.                             android:text="类别" />  
  394.                     </LinearLayout>  
  395.   
  396.                     <include layout="@layout/line_option_vertical_category_layout" />  
  397.   
  398.                     <LinearLayout  
  399.                         android:id="@+id/linear_9"  
  400.                         android:layout_width="0dip"  
  401.                         android:layout_height="match_parent"  
  402.                         android:layout_weight="1"  
  403.                         android:orientation="vertical" >  
  404.   
  405.                         <ImageView  
  406.                             android:id="@+id/iv_9"  
  407.                             android:layout_width="match_parent"  
  408.                             android:layout_height="0dip"  
  409.                             android:layout_marginTop="12dip"  
  410.                             android:layout_marginLeft="12dip"  
  411.                             android:layout_marginRight="12dip"  
  412.                             android:layout_marginBottom="5dip"  
  413.                             android:layout_weight="1"  
  414.                             android:src="@drawable/ic_launcher" />  
  415.   
  416.                         <TextView  
  417.                             android:id="@+id/tv_9"  
  418.                             android:layout_width="match_parent"  
  419.                             android:layout_marginBottom="7dip"  
  420.                             android:layout_height="wrap_content"  
  421.                             android:gravity="center"  
  422.                             android:text="类别" />  
  423.                     </LinearLayout>  
  424.                 </LinearLayout>  
  425.   
  426.                 <LinearLayout  
  427.                     android:id="@+id/hide_7"  
  428.                     android:layout_width="match_parent"  
  429.                     android:layout_height="wrap_content"  
  430.                     android:orientation="vertical"  
  431.                     android:visibility="gone" >  
  432.   
  433.                     <include layout="@layout/line_option_category_layout" />  
  434.   
  435.                     <com.zttmall.widget.MyGridView  
  436.                         android:id="@+id/gv_7"  
  437.                         android:layout_width="match_parent"  
  438.                         android:layout_height="wrap_content"  
  439.                         android:background="#66cccccc"  
  440.                         android:listSelector="@color/transparent"  
  441.                         android:numColumns="3" >  
  442.                     </com.zttmall.widget.MyGridView>  
  443.                 </LinearLayout>  
  444.   
  445.                 <LinearLayout  
  446.                     android:id="@+id/hide_8"  
  447.                     android:layout_width="match_parent"  
  448.                     android:layout_height="wrap_content"  
  449.                     android:orientation="vertical"  
  450.                     android:visibility="gone" >  
  451.   
  452.                     <include layout="@layout/line_option_category_layout" />  
  453.   
  454.                    <com.zttmall.widget.MyGridView  
  455.                         android:id="@+id/gv_8"  
  456.                         android:layout_width="match_parent"  
  457.                         android:layout_height="wrap_content"  
  458.                         android:background="#66cccccc"  
  459.                         android:listSelector="@color/transparent"  
  460.                         android:numColumns="3" >  
  461.                     </com.zttmall.widget.MyGridView>  
  462.                 </LinearLayout>  
  463.   
  464.                 <LinearLayout  
  465.                     android:id="@+id/hide_9"  
  466.                     android:layout_width="match_parent"  
  467.                     android:layout_height="wrap_content"  
  468.                     android:orientation="vertical"  
  469.                     android:visibility="gone" >  
  470.   
  471.                     <include layout="@layout/line_option_category_layout" />  
  472.   
  473.                     <com.zttmall.widget.MyGridView  
  474.                         android:id="@+id/gv_9"  
  475.                         android:layout_width="match_parent"  
  476.                         android:layout_height="wrap_content"  
  477.                         android:background="#66cccccc"  
  478.                         android:listSelector="@color/transparent"  
  479.                         android:numColumns="3" >  
  480.                     </com.zttmall.widget.MyGridView>  
  481.                 </LinearLayout>  
  482.   
  483.                 <include  
  484.                     android:id="@+id/hide_divider_3"   
  485.                     layout="@layout/line_option_category_layout" />  
  486.   
  487.                 <LinearLayout  
  488.                     android:id="@+id/line_4"  
  489.                     android:layout_width="match_parent"  
  490.                     android:layout_height="108dip"  
  491.                     android:orientation="horizontal" >  
  492.   
  493.                     <LinearLayout  
  494.                         android:id="@+id/linear_10"  
  495.                         android:layout_width="0dip"  
  496.                         android:layout_height="match_parent"  
  497.                         android:layout_weight="1"  
  498.                         android:orientation="vertical" >  
  499.   
  500.                         <ImageView  
  501.                             android:id="@+id/iv_10"  
  502.                             android:layout_width="match_parent"  
  503.                             android:layout_height="0dip"  
  504.                             android:layout_marginTop="12dip"  
  505.                             android:layout_marginLeft="12dip"  
  506.                             android:layout_marginRight="12dip"  
  507.                             android:layout_marginBottom="5dip"  
  508.                             android:layout_weight="1"  
  509.                             android:src="@drawable/ic_launcher" />  
  510.   
  511.                         <TextView  
  512.                             android:id="@+id/tv_10"  
  513.                             android:layout_width="match_parent"  
  514.                             android:layout_marginBottom="7dip"  
  515.                             android:layout_height="wrap_content"  
  516.                             android:gravity="center"  
  517.                             android:text="类别" />  
  518.                     </LinearLayout>  
  519.   
  520.                     <include layout="@layout/line_option_vertical_category_layout" />  
  521.   
  522.                     <LinearLayout  
  523.                         android:id="@+id/linear_11"  
  524.                         android:layout_width="0dip"  
  525.                         android:layout_height="match_parent"  
  526.                         android:layout_weight="1"  
  527.                         android:orientation="vertical" >  
  528.   
  529.                         <ImageView  
  530.                             android:id="@+id/iv_11"  
  531.                             android:layout_width="match_parent"  
  532.                             android:layout_height="0dip"  
  533.                             android:layout_marginTop="12dip"  
  534.                             android:layout_marginLeft="12dip"  
  535.                             android:layout_marginRight="12dip"  
  536.                             android:layout_marginBottom="5dip"  
  537.                             android:layout_weight="1"  
  538.                             android:src="@drawable/ic_launcher" />  
  539.   
  540.                         <TextView  
  541.                             android:id="@+id/tv_11"  
  542.                             android:layout_width="match_parent"  
  543.                             android:layout_height="wrap_content"  
  544.                             android:gravity="center"  
  545.                             android:layout_marginBottom="7dip"  
  546.                             android:text="类别" />  
  547.                     </LinearLayout>  
  548.   
  549.                     <include layout="@layout/line_option_vertical_category_layout" />  
  550.   
  551.                     <LinearLayout  
  552.                         android:id="@+id/linear_12"  
  553.                         android:layout_width="0dip"  
  554.                         android:layout_height="match_parent"  
  555.                         android:layout_weight="1"  
  556.                         android:orientation="vertical" >  
  557.   
  558.                         <ImageView  
  559.                             android:id="@+id/iv_12"  
  560.                             android:layout_width="match_parent"  
  561.                             android:layout_height="0dip"  
  562.                            android:layout_marginTop="12dip"  
  563.                             android:layout_marginLeft="12dip"  
  564.                             android:layout_marginRight="12dip"  
  565.                             android:layout_marginBottom="5dip"  
  566.                             android:layout_weight="1"  
  567.                             android:src="@drawable/ic_launcher" />  
  568.   
  569.                         <TextView  
  570.                             android:id="@+id/tv_12"  
  571.                             android:layout_width="match_parent"  
  572.                             android:layout_height="wrap_content"  
  573.                             android:layout_marginBottom="7dip"  
  574.                             android:gravity="center"  
  575.                             android:text="类别" />  
  576.                     </LinearLayout>  
  577.                 </LinearLayout>  
  578.   
  579.                 <include   
  580.                     android:id="@+id/hide_divider_4"  
  581.                     layout="@layout/line_option_category_layout" />  
  582.   
  583.                 <LinearLayout  
  584.                     android:id="@+id/hide_10"  
  585.                     android:layout_width="match_parent"  
  586.                     android:layout_height="wrap_content"  
  587.                     android:orientation="vertical"  
  588.                     android:visibility="gone" >  
  589.   
  590.                     <include layout="@layout/line_option_category_layout" />  
  591.   
  592.                    <com.zttmall.widget.MyGridView  
  593.                         android:id="@+id/gv_10"  
  594.                         android:layout_width="match_parent"  
  595.                         android:layout_height="wrap_content"  
  596.                         android:background="#66cccccc"  
  597.                         android:listSelector="@color/transparent"  
  598.                         android:numColumns="3" >  
  599.                     </com.zttmall.widget.MyGridView>  
  600.                 </LinearLayout>  
  601.   
  602.                 <LinearLayout  
  603.                     android:id="@+id/hide_11"  
  604.                     android:layout_width="match_parent"  
  605.                     android:layout_height="wrap_content"  
  606.                     android:orientation="vertical"  
  607.                     android:visibility="gone" >  
  608.   
  609.                     <include layout="@layout/line_option_category_layout" />  
  610.   
  611.                     <com.zttmall.widget.MyGridView  
  612.                         android:id="@+id/gv_11"  
  613.                         android:layout_width="match_parent"  
  614.                         android:layout_height="wrap_content"  
  615.                         android:background="#66cccccc"  
  616.                         android:listSelector="@color/transparent"  
  617.                         android:numColumns="3" >  
  618.                     </com.zttmall.widget.MyGridView>  
  619.                 </LinearLayout>  
  620.   
  621.                 <LinearLayout  
  622.                     android:id="@+id/hide_12"  
  623.                     android:layout_width="match_parent"  
  624.                     android:layout_height="wrap_content"  
  625.                     android:orientation="vertical"  
  626.                     android:visibility="gone" >  
  627.   
  628.                     <include layout="@layout/line_option_category_layout" />  
  629.   
  630.                     <com.zttmall.widget.MyGridView  
  631.                         android:id="@+id/gv_12"  
  632.                         android:layout_width="match_parent"  
  633.                         android:layout_height="wrap_content"  
  634.                         android:background="#66cccccc"  
  635.                         android:listSelector="@color/transparent"  
  636.                         android:numColumns="3" >  
  637.                     </com.zttmall.widget.MyGridView>  
  638.                 </LinearLayout>  
  639.             </LinearLayout>  
  640.         </ScrollView>  
  641.     </FrameLayout>  
  642.   
  643.     <FrameLayout  
  644.         android:id="@+id/prompt_framelayout"  
  645.         android:layout_width="fill_parent"  
  646.         android:layout_height="fill_parent"  
  647.         android:visibility="gone" >  
  648.   
  649.         <include layout="@layout/loading" />  
  650.   
  651.         <include layout="@layout/empty" />  
  652.   
  653.         <include layout="@layout/error" />  
  654.     </FrameLayout>  
  655.   
  656. </LinearLayout></span>  

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

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zttmall.widget;  
  2.   
  3. import android.content.Context;  
  4. import android.util.AttributeSet;  
  5. import android.widget.GridView;  
  6.   
  7. public class CustomGridView extends GridView {  
  8.     public CustomGridView(Context context) {  
  9.         super(context);  
  10.     }  
  11.   
  12.     public CustomGridView(Context context, AttributeSet attrs) {  
  13.         super(context, attrs);  
  14.     }  
  15.   
  16.     public CustomGridView(Context context, AttributeSet attrs, int defStyle) {  
  17.         super(context, attrs, defStyle);  
  18.     }  
  19.   
  20.     @Override  
  21.     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
  22.         int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,  
  23.                 MeasureSpec.AT_MOST);  
  24.         super.onMeasure(widthMeasureSpec, expandSpec);  
  25.     }  
  26. }  

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

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. package com.zttmall.fragment;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.HashMap;  
  5. import java.util.List;  
  6. import tv.pps.modules.imagelogic.ImageLogic;  
  7. import android.content.Intent;  
  8. import android.os.Bundle;  
  9. import android.os.Handler;  
  10. import android.view.LayoutInflater;  
  11. import android.view.View;  
  12. import android.view.View.OnClickListener;  
  13. import android.view.ViewGroup;  
  14. import android.widget.AdapterView;  
  15. import android.widget.AdapterView.OnItemClickListener;  
  16. import android.widget.FrameLayout;  
  17. import android.widget.GridView;  
  18. import android.widget.ImageView;  
  19. import android.widget.LinearLayout;  
  20. import android.widget.TextView;  
  21.   
  22. import com.alibaba.fastjson.JSON;  
  23. import com.zttmall.BaseFragment;  
  24. import com.zttmall.ZTTMallApplication;  
  25. import com.zttmall.adapter.SubCategoryAdapter;  
  26. import com.zttmall.common.DefineView;  
  27. import com.zttmall.common.DeliverConsts;  
  28. import com.zttmall.common.RequestURL;  
  29. import com.zttmall.listlogic.ListFetcher;  
  30. import com.zttmall.listlogic.ListSimpleParse;  
  31. import com.zttmall.model.category.CategoryModel;  
  32. import com.zttmall.model.category.ShowCategoryModel;  
  33. import com.zttmall.model.category.SubCategoryModel;  
  34. import com.zttmall.ui.ClassifyThreeCategoryActivity;  
  35. import com.zttmall.ui.R;  
  36. import com.zttmall.utils.Log;  
  37.   
  38. /** 
  39.  * 商品分类功能 
  40.  *  
  41.  * @author jiangqq 
  42.  *  
  43.  */  
  44. public class ClassifyFragment extends BaseFragment implements DefineView {  
  45.     private View mView;  
  46.     private TextView tab_bar_title_one;  
  47.     private ShowCategoryModel model;  
  48.   
  49.     private FrameLayout frame_content;  
  50.     private FrameLayout prompt_framelayout;  
  51.     private LinearLayout loading;  
  52.     private LinearLayout empty;  
  53.     private LinearLayout error;  
  54.   
  55.     String descString;  
  56.     private ListFetcher mListWorker;  
  57.     private HashMap<String, String> requestMap;  
  58.   
  59.     private SubCategoryAdapter mSubCategoryAdapter;  
  60.     ImageLogic mImageLogic;  
  61.     private List<LinearLayout> linearList = new ArrayList<LinearLayout>();  
  62.     private List<ImageView> ivList = new ArrayList<ImageView>();  
  63.     private List<TextView> tvList = new ArrayList<TextView>();  
  64.     private List<LinearLayout> hideList = new ArrayList<LinearLayout>();  
  65.     private List<GridView> gvList = new ArrayList<GridView>();  
  66.   
  67.     private Handler mHandler = new Handler() {  
  68.         public void handleMessage(android.os.Message msg) {  
  69.             if (msg.what == ListFetcher.LIST_OK) {  
  70.                 getDataOk();  
  71.             } else if (msg.what == ListFetcher.LIST_ERROR) {  
  72.                 getDataError();  
  73.             }  
  74.   
  75.         };  
  76.     };  
  77.   
  78.     @Override  
  79.     public View onCreateView(LayoutInflater inflater, ViewGroup container,  
  80.             Bundle savedInstanceState) {  
  81.         if (mView == null) {  
  82.             mView = inflater.inflate(R.layout.classify_fragment_layout,  
  83.                     container, false);  
  84.             initView();  
  85.             initValidata();  
  86.             initListener();  
  87.             bindData();  
  88.         }  
  89.         return mView;  
  90.     }  
  91.   
  92.     @Override  
  93.     public void initView() {  
  94.         tab_bar_title_one = (TextView) mView  
  95.                 .findViewById(R.id.tab_bar_title_one);  
  96.         tab_bar_title_one.setText(R.string.string_classify_name);  
  97.         frame_content = (FrameLayout) mView.findViewById(R.id.frame_content);  
  98.         prompt_framelayout = (FrameLayout) mView  
  99.                 .findViewById(R.id.prompt_framelayout);  
  100.         loading = (LinearLayout) mView.findViewById(R.id.loading);  
  101.         empty = (LinearLayout) mView.findViewById(R.id.empty);  
  102.         error = (LinearLayout) mView.findViewById(R.id.error);  
  103.   
  104.         initViewList();  
  105.   
  106.     }  
  107.   
  108.     public void initViewList() {  
  109.   
  110.         /* 
  111.          * line1 = (LinearLayout) mView.findViewById(R.id.line_1); line2 = 
  112.          * (LinearLayout) mView.findViewById(R.id.line_2); line3 = 
  113.          * (LinearLayout) mView.findViewById(R.id.line_3); line4 = 
  114.          * (LinearLayout) mView.findViewById(R.id.line_4); 
  115.          */  
  116.   
  117.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_1));  
  118.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_2));  
  119.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_3));  
  120.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_4));  
  121.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_5));  
  122.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_6));  
  123.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_7));  
  124.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_8));  
  125.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_9));  
  126.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_10));  
  127.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_11));  
  128.         linearList.add((LinearLayout) mView.findViewById(R.id.linear_12));  
  129.   
  130.         ivList.add((ImageView) mView.findViewById(R.id.iv_1));  
  131.         ivList.add((ImageView) mView.findViewById(R.id.iv_2));  
  132.         ivList.add((ImageView) mView.findViewById(R.id.iv_3));  
  133.         ivList.add((ImageView) mView.findViewById(R.id.iv_4));  
  134.         ivList.add((ImageView) mView.findViewById(R.id.iv_5));  
  135.         ivList.add((ImageView) mView.findViewById(R.id.iv_6));  
  136.         ivList.add((ImageView) mView.findViewById(R.id.iv_7));  
  137.         ivList.add((ImageView) mView.findViewById(R.id.iv_8));  
  138.         ivList.add((ImageView) mView.findViewById(R.id.iv_9));  
  139.         ivList.add((ImageView) mView.findViewById(R.id.iv_10));  
  140.         ivList.add((ImageView) mView.findViewById(R.id.iv_11));  
  141.         ivList.add((ImageView) mView.findViewById(R.id.iv_12));  
  142.   
  143.         tvList.add((TextView) mView.findViewById(R.id.tv_1));  
  144.         tvList.add((TextView) mView.findViewById(R.id.tv_2));  
  145.         tvList.add((TextView) mView.findViewById(R.id.tv_3));  
  146.         tvList.add((TextView) mView.findViewById(R.id.tv_4));  
  147.         tvList.add((TextView) mView.findViewById(R.id.tv_5));  
  148.         tvList.add((TextView) mView.findViewById(R.id.tv_6));  
  149.         tvList.add((TextView) mView.findViewById(R.id.tv_7));  
  150.         tvList.add((TextView) mView.findViewById(R.id.tv_8));  
  151.         tvList.add((TextView) mView.findViewById(R.id.tv_9));  
  152.         tvList.add((TextView) mView.findViewById(R.id.tv_10));  
  153.         tvList.add((TextView) mView.findViewById(R.id.tv_11));  
  154.         tvList.add((TextView) mView.findViewById(R.id.tv_12));  
  155.   
  156.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_1));  
  157.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_2));  
  158.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_3));  
  159.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_4));  
  160.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_5));  
  161.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_6));  
  162.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_7));  
  163.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_8));  
  164.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_9));  
  165.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_10));  
  166.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_11));  
  167.         hideList.add((LinearLayout) mView.findViewById(R.id.hide_12));  
  168.   
  169.         gvList.add((GridView) mView.findViewById(R.id.gv_1));  
  170.         gvList.add((GridView) mView.findViewById(R.id.gv_2));  
  171.         gvList.add((GridView) mView.findViewById(R.id.gv_3));  
  172.         gvList.add((GridView) mView.findViewById(R.id.gv_4));  
  173.         gvList.add((GridView) mView.findViewById(R.id.gv_5));  
  174.         gvList.add((GridView) mView.findViewById(R.id.gv_6));  
  175.         gvList.add((GridView) mView.findViewById(R.id.gv_7));  
  176.         gvList.add((GridView) mView.findViewById(R.id.gv_8));  
  177.         gvList.add((GridView) mView.findViewById(R.id.gv_9));  
  178.         gvList.add((GridView) mView.findViewById(R.id.gv_10));  
  179.         gvList.add((GridView) mView.findViewById(R.id.gv_11));  
  180.         gvList.add((GridView) mView.findViewById(R.id.gv_12));  
  181.     }  
  182.   
  183.     @Override  
  184.     public void initValidata() {  
  185.         // TODO Auto-generated method stub  
  186.         mImageLogic = ImageLogic.create(getActivity());  
  187.         mImageLogic.configBitmapMaxHeight(120);  
  188.         mImageLogic.configBitmapMaxWidth(120);  
  189.   
  190.         mListWorker = new ListFetcher(getActivity(),  
  191.                 ListSimpleParse.DEFAULT_JSON_CATEGORY, mHandler);  
  192.         mListWorker.loadJsonDataList(RequestURL.CATEGORY_URL);  
  193.   
  194.         mSubCategoryAdapter = new SubCategoryAdapter(getActivity());  
  195.   
  196.         frame_content.setVisibility(View.GONE);  
  197.         prompt_framelayout.setVisibility(View.VISIBLE);  
  198.         loading.setVisibility(View.VISIBLE);  
  199.         empty.setVisibility(View.GONE);  
  200.         error.setVisibility(View.GONE);  
  201.     }  
  202.   
  203.     @Override  
  204.     public void initListener() {  
  205.         // TODO Auto-generated method stub  
  206.         error.setOnClickListener(new OnClickListener() {  
  207.   
  208.             @Override  
  209.             public void onClick(View v) {  
  210.                 // TODO Auto-generated method stub  
  211.                 mListWorker.loadJsonDataList(RequestURL.CATEGORY_URL);  
  212.                 frame_content.setVisibility(View.GONE);  
  213.                 prompt_framelayout.setVisibility(View.VISIBLE);  
  214.                 loading.setVisibility(View.VISIBLE);  
  215.                 empty.setVisibility(View.GONE);  
  216.                 error.setVisibility(View.GONE);  
  217.             }  
  218.         });  
  219.         for (int i = 0; i < linearList.size(); i++) {  
  220.             linearList.get(i).setOnClickListener(  
  221.                     new MyCustomerOnclickListener());  
  222.         }  
  223.     }  
  224.   
  225.     @Override  
  226.     public void bindData() {  
  227.         // TODO Auto-generated method stub  
  228.   
  229.     }  
  230.   
  231.     @Override  
  232.     public void getPageData() {  
  233.         // TODO Auto-generated method stub  
  234.   
  235.     }  
  236.   
  237.     @Override  
  238.     public void getDataOk() {  
  239.         // TODO Auto-generated method stub  
  240.         HashMap<String, Object> tempMap = ZTTMallApplication.getInstance()  
  241.                 .getTempMap();  
  242.         model = (ShowCategoryModel) tempMap  
  243.                 .get(DeliverConsts.KEY_CATEGORY_MODEL);  
  244.         if (model != null && model.getCode().equals("1")  
  245.                 && "SUCCESS".equals(model.getMsg())) {  
  246.             if (model.getData() != null && model.getData().size() > 0) {  
  247.                 showData(model);  
  248.                 frame_content.setVisibility(View.VISIBLE);  
  249.                 prompt_framelayout.setVisibility(View.GONE);  
  250.                 loading.setVisibility(View.GONE);  
  251.                 empty.setVisibility(View.GONE);  
  252.                 error.setVisibility(View.GONE);  
  253.             } else {  
  254.                 frame_content.setVisibility(View.GONE);  
  255.                 prompt_framelayout.setVisibility(View.VISIBLE);  
  256.                 loading.setVisibility(View.GONE);  
  257.                 empty.setVisibility(View.VISIBLE);  
  258.                 error.setVisibility(View.GONE);  
  259.             }  
  260.         } else {  
  261.             frame_content.setVisibility(View.GONE);  
  262.             prompt_framelayout.setVisibility(View.VISIBLE);  
  263.             loading.setVisibility(View.GONE);  
  264.             empty.setVisibility(View.GONE);  
  265.             error.setVisibility(View.VISIBLE);  
  266.         }  
  267.     }  
  268.   
  269.     @Override  
  270.     public void getDataError() {  
  271.         // TODO Auto-generated method stub  
  272.   
  273.     }  
  274.   
  275.     @Override  
  276.     public void getDataRefresh() {  
  277.         // TODO Auto-generated method stub  
  278.   
  279.     }  
  280.   
  281.     class MyCustomerOnclickListener implements OnClickListener {  
  282.   
  283.         @Override  
  284.         public void onClick(View v) {  
  285.             // TODO Auto-generated method stub  
  286.             switch (v.getId()) {  
  287.             case R.id.linear_1:  
  288.                 showOrHide(0, model.getData().get(0).getSub_category());  
  289.                 break;  
  290.             case R.id.linear_2:  
  291.                 showOrHide(1, model.getData().get(1).getSub_category());  
  292.                 break;  
  293.             case R.id.linear_3:  
  294.                 showOrHide(2, model.getData().get(2).getSub_category());  
  295.                 break;  
  296.             case R.id.linear_4:  
  297.                 showOrHide(3, model.getData().get(3).getSub_category());  
  298.                 break;  
  299.             case R.id.linear_5:  
  300.                 showOrHide(4, model.getData().get(4).getSub_category());  
  301.                 break;  
  302.             case R.id.linear_6:  
  303.                 showOrHide(5, model.getData().get(5).getSub_category());  
  304.                 break;  
  305.             case R.id.linear_7:  
  306.                 showOrHide(6, model.getData().get(6).getSub_category());  
  307.                 break;  
  308.             case R.id.linear_8:  
  309.                 showOrHide(7, model.getData().get(7).getSub_category());  
  310.                 break;  
  311.             case R.id.linear_9:  
  312.                 showOrHide(8, model.getData().get(8).getSub_category());  
  313.                 break;  
  314.             case R.id.linear_10:  
  315.                 showOrHide(9, model.getData().get(9).getSub_category());  
  316.                 break;  
  317.             case R.id.linear_11:  
  318.                 showOrHide(10, model.getData().get(10).getSub_category());  
  319.                 break;  
  320.             case R.id.linear_12:  
  321.                 showOrHide(11, model.getData().get(11).getSub_category());  
  322.                 break;  
  323.             }  
  324.         }  
  325.   
  326.         void showOrHide(final int i, final List<SubCategoryModel> list) {  
  327.             if (list != null && list.size() > 0) {  
  328.                 mSubCategoryAdapter.setmList(list);  
  329.                 gvList.get(i).setAdapter(mSubCategoryAdapter);  
  330.   
  331.                 descString = model.getData().get(i).getDesc();  
  332.                 mSubCategoryAdapter.notifyDataSetChanged();  
  333.   
  334.                 for (int j = 0; j < hideList.size(); j++) {  
  335.                     if (j != i) {  
  336.                         hideList.get(j).setVisibility(View.GONE);  
  337.                     } else {  
  338.                         if (hideList.get(i).getVisibility() == View.VISIBLE) {  
  339.                             hideList.get(i).setVisibility(View.GONE);  
  340.                         } else {  
  341.                             hideList.get(i).setVisibility(View.VISIBLE);  
  342.                             gvList.get(i).setOnItemClickListener(  
  343.                                     new OnItemClickListener() {  
  344.   
  345.                                         @Override  
  346.                                         public void onItemClick(  
  347.                                                 AdapterView<?> parent,  
  348.                                                 View view, int position, long id) {  
  349.                                             // TODO Auto-generated method stub  
  350.                                             Intent _Intent = new Intent(  
  351.                                                     getActivity(),  
  352.                                                     ClassifyThreeCategoryActivity.class);  
  353.                                             _Intent.putExtra("title",  
  354.                                                     descString);  
  355.                                             _Intent.putExtra(  
  356.                                                     "content",  
  357.                                                     JSON.toJSONString(list  
  358.                                                             .get(position)  
  359.                                                             .getThree_category()));  
  360.                                             startActivity(_Intent);  
  361.                                         }  
  362.                                     });  
  363.                         }  
  364.                     }  
  365.                 }  
  366.             } else {  
  367.                 List<SubCategoryModel> lists = new ArrayList<SubCategoryModel>();  
  368.                 mSubCategoryAdapter.setmList(lists);  
  369.                 mSubCategoryAdapter.notifyDataSetChanged();  
  370.             }  
  371.   
  372.         }  
  373.   
  374.     }  
  375.   
  376.     void showData(ShowCategoryModel model) {  
  377.         List<CategoryModel> mLists = model.getData();  
  378.         int length = model.getData().size();  
  379.         for (int i = 0; i < model.getData().size(); i++) {  
  380.             tvList.get(i).setText(model.getData().get(i).getTitle());  
  381.             mImageLogic  
  382.                     .display(ivList.get(i), model.getData().get(i).getIcon());  
  383.         }  
  384.         int temp = (length - 1) / 3 + 2;  
  385.         for (int i = length; i < linearList.size(); i++) {  
  386.             linearList.get(i).setVisibility(View.INVISIBLE);  
  387.         }  
  388.         if (linearList.size() > (temp - 1) * 3)  
  389.             for (int i = (temp - 1) * 3; i < linearList.size(); i++) {  
  390.                 linearList.get(i).setVisibility(View.GONE);  
  391.             }  
  392.   
  393.     }  
  394. }  
相应的信息实体类(Model)就不贴了,直接上一篇博客就行了。

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

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


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值