精华内容
下载资源
问答
  • <p>I'm trying to iterate through all the rows in a MYSQL table given the column name.... ... ...$dbcon = getConnection();...$currentUser= $_COOKIE['currentUser'];...$getIpQuery = mysqli_query($dbcon, "SELECT $...
  • <p>Heres the scenario: I am supposed to make a small site where user can register, I am using a table named users with fields <pre><code>userid int unsigned auto_increment, name varchar(50), ...
  • <p>say with a structure like this., columns are : <h2>first_name | second_name | middle_name | last_name <p>Now, suppose i have a form that requires to enter a "name"..but not specifying what ...
  • 只需上传或指向您要清除的数据,然后通过点击界面就可以开始合并列条目。 无需编码-尽管它确实为想要的ETL管道吐出了可重现的脚本! 我们的第一个版本侧重于实体合并任务(在数据集之内和之间),但是我们计划在...
  • 获取一的所有条目

    2016-09-18 13:47:14
    <p>Let's say I have a table in my MySQL database called 'Users', and that table has two columns called 'Username' and 'Password'. At one point I want to get all of the usernames, without the ...
  • <p>I want to get all the entries from mysql table having duplicate mobile_no and email_id, i tried the following query but no luck <pre><code>SELECT * FROM duplicate WHERE (mobile_no = (SELECT ...
  • 中的条目转换为链接的 ko-grid 扩展。
  • 用android.support.v4.View.ViewPager类写的一个小Demo,可以用来滑动浏览各项条目,简单好用,适合快速上手ViewPager实现滑动效果。
  • 用这个: =IF(COUNTIF($B$1:$B$100,A1),"A in B","A NOT in B") 同时, Excel 的 Data > Data Tools 有一个 Remove Duplicates 功能非常好用。 转载于:...

    用这个:

    =IF(COUNTIF($B$1:$B$100,A1),"A in B","A NOT in B")

    同时, Excel 的 Data > Data Tools 有一个 Remove Duplicates 功能非常好用。

    转载于:https://www.cnblogs.com/backpacker/archive/2012/11/22/2781928.html

    展开全文
  • 对于这种需求,想要通过SQL实现的话,不能使用 decode 函数(条目相同的需求,可以使用 decode 函数来实现) 方法一,在 Oracle 11g,可以使用 LISTAGG 这个分析函数来实现 SELECT report_date,  LISTAGG...
    --创建测试表
    create table test(report_date date,activity_name varchar2(15),amount number);


    insert into test values(to_date('2015-10-01','yyyy-mm-dd'),'活动一',1300);
    insert into test values(to_date('2015-10-02','yyyy-mm-dd'),'活动一',500);
    insert into test values(to_date('2015-10-02','yyyy-mm-dd'),'活动二',800);
    insert into test values(to_date('2015-10-03','yyyy-mm-dd'),'活动一',900);
    insert into test values(to_date('2015-10-03','yyyy-mm-dd'),'活动二',1500);
    insert into test values(to_date('2015-10-03','yyyy-mm-dd'),'活动三',3500);
    commit;


    SQL> select * from test;


    REPORT_DAT ACTIVITY_NAME  AMOUNT
    ----------         ---------------           ----------
    2015-10-01 活动一                1300
    2015-10-02 活动一                 500
    2015-10-02 活动二                 800
    2015-10-03 活动一                 900
    2015-10-03 活动二                1500
    2015-10-03 活动三                3500


    已选择6行。


    想要实现的效果是:


    ---------- --------------- ----------
    2015-10-01 活动一                1300
    2015-10-02 活动一                 500 活动二                 800
    2015-10-03 活动一                 900 活动二                1500 活动三                3500


    可以发现,列的数据条目是不规则的


    对于这种需求,想要通过SQL实现的话,不能使用 decode 函数(列的条目相同的需求,可以使用 decode 函数来实现)


    方法一,在 Oracle 11g,可以使用 LISTAGG 这个分析函数来实现

    SELECT report_date,
           LISTAGG(activity_name || ',  ' || amount || ', ') within GROUP(ORDER BY report_date) info
      FROM test
     GROUP BY report_date;


    REPORT_DAT INFO
    ---------- ---------------------------------------------
    2015-10-01 活动一,  1300,
    2015-10-02 活动二,  800, 活动一,  500,
    2015-10-03 活动二,  1500, 活动三,  3500, 活动一,  900,


    方法二,通过层次函数 CONEECT BY 实现

    with tmp as
     (select report_date, activity_name || ', ' || amount info, rn
        from (select report_date,
                     activity_name,
                     ROW_NUMBER() OVER(PARTITION BY report_date ORDER BY activity_name) rn,
                     amount
                from test))
    select a.report_date, b.message
      from(
    select report_date, max(level_no) no
      from(
    select report_date, LTRIM(SYS_CONNECT_BY_PATH(info, '/ '), '/') message, level level_no
      from tmp
    connect by prior report_date = report_date and prior rn = rn + 1)
     group by report_date) a,(
    select report_date, LTRIM(SYS_CONNECT_BY_PATH(info, '/ '), '/') message, level level_no
      from tmp
    connect by prior report_date = report_date and prior rn = rn - 1) b
     where a.report_date = b.report_date and a.no = b.level_no;

    方法三,在 Oracle 10g ,使用 WM_CONCAT 函数来实现

    SELECT report_date, MAX(info)
    from (SELECT report_date,
           WM_CONCAT(activity_name || ',  ' || amount || ', ') OVER (PARTITION BY report_date ORDER BY report_date) info
      FROM test)
    GROUP BY report_date;

    来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26506993/viewspace-1869259/,如需转载,请注明出处,否则将追究法律责任。

    转载于:http://blog.itpub.net/26506993/viewspace-1869259/

    展开全文
  • ... <pre><code><?... $p_sql = "SELECT * FROM products";... $p_query = mysqli_query($db_conx, $p_sql);... $productData = mysqli_fetch_array($p_query, MYSQL_ASSOC);...<p>I know within my for loop I don't ...
  • 原作者:跃然一笑 让我们从虚拟数据开始: from pyspark.sql import Row row = Row("v", "x", "y", "z") ... row(0.0, 1, 2, 3.0), row(None, 3, 4, 5.0), ... row(None, None, 6, 7.0), row(float("Nan"), 8, 9, ...

     

    原作者:跃然一笑

    让我们从虚拟数据开始:

     

    from pyspark.sql import Row

     

    row = Row("v", "x", "y", "z")

    df = sc.parallelize([

        row(0.0, 1, 2, 3.0), row(None, 3, 4, 5.0),

        row(None, None, 6, 7.0), row(float("Nan"), 8, 9, float("NaN"))

    ]).toDF()

     

    ## +----+----+---+---+

    ## |   v|   x|  y|  z|

    ## +----+----+---+---+

    ## | 0.0|   1|  2|3.0|

    ## |null|   3|  4|5.0|

    ## |null|null|  6|7.0|

    ## | NaN|   8|  9|NaN|

    ## +----+----+---+---+

    您只需要一个简单的聚合:

     

    from pyspark.sql.functions import col, count, isnan, lit, sum

     

    def count_not_null(c, nan_as_null=False):

        """Use conversion between boolean and integer

        - False -> 0

        - True ->  1

        """

        pred = col(c).isNotNull() & (~isnan(c) if nan_as_null else lit(True))

        return sum(pred.cast("integer")).alias(c)

     

    df.agg(*[count_not_null(c) for c in df.columns]).show()

     

    ## +---+---+---+---+

    ## |  v|  x|  y|  z|

    ## +---+---+---+---+

    ## |  2|  3|  4|  4|

    ## +---+---+---+---+

    或者,如果你想享受NaN一个NULL:

     

    df.agg(*[count_not_null(c, True) for c in df.columns]).show()

     

    ## +---+---+---+---+

    ## |  v|  x|  y|  z|

    ## +---+---+---+---+

    ## |  1|  3|  4|  3|

    ## +---+---+---+---

    您还可以利用SQL NULL语义来实现相同的结果,而无需创建自定义函数:

     

    df.agg(*[

        count(c).alias(c)    # vertical (column-wise) operations in SQL ignore NULLs

        for c in df.columns

    ]).show()

     

    ## +---+---+---+

    ## |  x|  y|  z|

    ## +---+---+---+

    ## |  1|  2|  3|

    ## +---+---+---+

    但这不适用于NaNs。

     

    如果您喜欢分数:

     

    exprs = [(count_not_null(c) / count("*")).alias(c) for c in df.columns]

    df.agg(*exprs).show()

     

    ## +------------------+------------------+---+

    ## |                 x|                 y|  z|

    ## +------------------+------------------+---+

    ## |0.3333333333333333|0.6666666666666666|1.0|

    ## +------------------+------------------+---+

    要么

     

    # COUNT(*) is equivalent to COUNT(1) so NULLs won't be an issue

    df.select(*[(count(c) / count("*")).alias(c) for c in df.columns]).show()

     

    ## +------------------+------------------+---+

    ## |                 x|                 y|  z|

    ## +------------------+------------------+---+

    ## |0.3333333333333333|0.6666666666666666|1.0|

    ## +------------------+------------------+---+

    相当于Scala:

     

    import org.apache.spark.sql.Column

    import org.apache.spark.sql.functions.{col, isnan, sum}

     

    type JDouble = java.lang.Double

     

    val df = Seq[(JDouble, JDouble, JDouble, JDouble)](

      (0.0, 1, 2, 3.0), (null, 3, 4, 5.0),

      (null, null, 6, 7.0), (java.lang.Double.NaN, 8, 9, java.lang.Double.NaN)

    ).toDF()

     

     

    def count_not_null(c: Column, nanAsNull: Boolean = false) = {

      val pred = c.isNotNull and (if (nanAsNull) not(isnan(c)) else lit(true))

      sum(pred.cast("integer"))

    }

     

    df.select(df.columns map (c => count_not_null(col(c)).alias(c)): _*).show

    // +---+---+---+---+                                                               

    // | _1| _2| _3| _4|

    // +---+---+---+---+

    // |  2|  3|  4|  4|

    // +---+---+---+---+

     

     df.select(df.columns map (c => count_not_null(col(c), true).alias(c)): _*).show

     // +---+---+---+---+

     // | _1| _2| _3| _4|

     // +---+---+---+---+

     // |  1|  3|  4|  3|

     // +---+---+---+---+

    展开全文
  • <p>how can i write a query to list duplicate entries in a database from the same category. The duplicates have the same value in the "name" column. I need to list only the duplicates in the same ...
  • <p>I would like to come up with a standard practice to prevent any tables from having duplicates where it matters. In most cases duplicates are a combination of variables rather than one....
  • // 当前的条目是普通recyclerView的条目     public   static   final   int  NORMAL_RECYCLER_VIEW_ITEM =  1 ;      @Override     protected   void  onCreate(Bundle savedInstanceState) { ...

    用RecycleView来实现布局形式,默认只能指定一种布局格式,但是实际中我们的布局经常会用到多种类型的布局方式。如何实现呢?

    今天来说下常用的2钟方式。

    第一种:

    通过自定义addHeadView方法来添加头布局

    RecycleViewWithHead.Java

    1. import android.app.Activity;  
    2. import android.os.Bundle;  
    3. import android.support.v7.widget.GridLayoutManager;  
    4. import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;  
    5. import android.support.v7.widget.RecyclerView;  
    6. import android.view.View;  
    7.   
    8. public class RecycleViewWithHead extends Activity {  
    9.   
    10.     private RecyclerView rcv;  
    11.     // 当前的条目是recyclerView的头布局  
    12.     public static final int HEADER_RECYCLER_VIEW_ITEM = 0;  
    13.     // 当前的条目是普通recyclerView的条目  
    14.     public static final int NORMAL_RECYCLER_VIEW_ITEM = 1;  
    15.   
    16.     @Override  
    17.     protected void onCreate(Bundle savedInstanceState) {  
    18.         // TODO Auto-generated method stub  
    19.         super.onCreate(savedInstanceState);  
    20.         setContentView(R.layout.activity_recycle);  
    21.         rcv = (RecyclerView) findViewById(R.id.rcv);  
    22.         // 设置布局管理  
    23.         GridLayoutManager manager = new GridLayoutManager(this2);  
    24.         // 设置布局管理一条数据占用几行,如果是头布局则头布局自己占用一行  
    25.         manager.setSpanSizeLookup(new SpanSizeLookup() {  
    26.             @Override  
    27.             public int getSpanSize(int postion) {  
    28.                 if (postion == 0) {  
    29.                     return 2;  
    30.                 } else {  
    31.                     return 1;  
    32.                 }  
    33.             }  
    34.         });  
    35.         rcv.setLayoutManager(manager);  
    36.         MyRecycleAdapter adapter = new MyRecycleAdapter(  
    37.                 RecycleViewWithHead.this20);  
    38.         View view = View.inflate(this, R.layout.head, null);  
    39.         adapter.addHeadView(view);  
    40.         rcv.setAdapter(adapter);  
    41.     }  
    42. }  
    import android.app.Activity;
    import android.os.Bundle;
    import android.support.v7.widget.GridLayoutManager;
    import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;
    import android.support.v7.widget.RecyclerView;
    import android.view.View;
    
    public class RecycleViewWithHead extends Activity {
    
        private RecyclerView rcv;
        // 当前的条目是recyclerView的头布局
        public static final int HEADER_RECYCLER_VIEW_ITEM = 0;
        // 当前的条目是普通recyclerView的条目
        public static final int NORMAL_RECYCLER_VIEW_ITEM = 1;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_recycle);
            rcv = (RecyclerView) findViewById(R.id.rcv);
            // 设置布局管理
            GridLayoutManager manager = new GridLayoutManager(this, 2);
            // 设置布局管理一条数据占用几行,如果是头布局则头布局自己占用一行
            manager.setSpanSizeLookup(new SpanSizeLookup() {
                @Override
                public int getSpanSize(int postion) {
                    if (postion == 0) {
                        return 2;
                    } else {
                        return 1;
                    }
                }
            });
            rcv.setLayoutManager(manager);
            MyRecycleAdapter adapter = new MyRecycleAdapter(
                    RecycleViewWithHead.this, 20);
            View view = View.inflate(this, R.layout.head, null);
            adapter.addHeadView(view);
            rcv.setAdapter(adapter);
        }
    }
    


    布局文件activity_recycle.xml

    1. <RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”  
    2.     xmlns:tools=“http://schemas.android.com/tools”  
    3.     android:layout_width=“match_parent”  
    4.     android:layout_height=“match_parent”>  
    5.   
    6.   
    7.     <android.support.v7.widget.RecyclerView  
    8.         android:id=“@+id/rcv”  
    9.         android:layout_width=“match_parent”  
    10.         android:layout_height=“wrap_content” />  
    11.   
    12.   
    13. </RelativeLayout>  
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rcv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
    
    </RelativeLayout>


    头布局文件head.xml

    1. <?xml version=“1.0” encoding=“utf-8”?>  
    2. <RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”  
    3.     android:layout_width=“match_parent”  
    4.     android:layout_height=“match_parent” >  
    5.   
    6.     <ImageView  
    7.         android:id=“@+id/iv_head”  
    8.         android:layout_width=“80dp”  
    9.         android:layout_height=“80dp”  
    10.         android:layout_margin=“10dp”  
    11.         android:src=“@drawable/head” />  
    12.   
    13.     <TextView  
    14.         android:id=“@+id/tv_head”  
    15.         android:layout_width=“wrap_content”  
    16.         android:layout_height=“wrap_content”  
    17.         android:layout_alignTop=“@+id/iv_head”  
    18.         android:layout_toRightOf=“@+id/iv_head”  
    19.         android:text=“这是一张熊猫的图片” />  
    20.   
    21.     <ImageView  
    22.         android:id=“@+id/iv_head_bottom”  
    23.         android:layout_width=“wrap_content”  
    24.         android:layout_height=“wrap_content”  
    25.         android:layout_alignBottom=“@+id/iv_head”  
    26.         android:layout_toRightOf=“@+id/iv_head”  
    27.         android:src=“@drawable/type” />  
    28.   
    29. </RelativeLayout>  
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <ImageView
            android:id="@+id/iv_head"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_margin="10dp"
            android:src="@drawable/head" />
    
        <TextView
            android:id="@+id/tv_head"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/iv_head"
            android:layout_toRightOf="@+id/iv_head"
            android:text="这是一张熊猫的图片" />
    
        <ImageView
            android:id="@+id/iv_head_bottom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/iv_head"
            android:layout_toRightOf="@+id/iv_head"
            android:src="@drawable/type" />
    
    </RelativeLayout>



    适配器MyRecycleAdapter.java

    1. import android.content.Context;  
    2. import android.support.v7.widget.RecyclerView;  
    3. import android.support.v7.widget.RecyclerView.ViewHolder;  
    4. import android.view.LayoutInflater;  
    5. import android.view.View;  
    6. import android.view.View.OnClickListener;  
    7. import android.view.ViewGroup;  
    8. import android.widget.Toast;  
    9.   
    10. public class MyRecycleAdapter extends  
    11.         RecyclerView.Adapter<MyRecycleAdapterHolder> {  
    12.   
    13.     private View headView;  
    14.     private Context mContext;  
    15.     private int count;  
    16.   
    17.     MyRecycleAdapter(Context mContext, int count) {  
    18.         this.count = count;  
    19.         this.mContext = mContext;  
    20.     }  
    21.   
    22.     /** 
    23.      * 设置数据源总的条目 
    24.      */  
    25.     @Override  
    26.     public int getItemCount() {  
    27.         //返回条目数加头布局个数  
    28.         return count + 1;  
    29.     }  
    30.   
    31.     @Override  
    32.     public void onBindViewHolder(MyRecycleAdapterHolder holder,  
    33.             final int position) {  
    34.         int itemViewType = getItemViewType(position);  
    35.         // 头部  
    36.         if (itemViewType == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {  
    37.             return;  
    38.         } else if (itemViewType == RecycleViewWithHead.NORMAL_RECYCLER_VIEW_ITEM) {//普通条目  
    39.             holder.iv_item_icon.setOnClickListener(new OnClickListener() {  
    40.                 @Override  
    41.                 public void onClick(View v) {  
    42.                     Toast.makeText(mContext, (position - 1) + “”0).show();  
    43.                 }  
    44.             });  
    45.         }  
    46.   
    47.     }  
    48.   
    49.     @Override  
    50.     public MyRecycleAdapterHolder onCreateViewHolder(ViewGroup parent,  
    51.             int viewType) {  
    52.         View root = null;  
    53.         if (viewType == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {  
    54.             root = headView;  
    55.         } else {  
    56.             root = LayoutInflater.from(mContext).inflate(R.layout.item, parent,  
    57.                     false);  
    58.         }  
    59.         return new MyRecycleAdapterHolder(root, viewType);  
    60.     }  
    61.   
    62.     /** 
    63.      * 添加自定义头部 
    64.      */  
    65.     public void addHeadView(View view) {  
    66.         this.headView = view;  
    67.     }  
    68.   
    69.     @Override  
    70.     public int getItemViewType(int position) {  
    71.   
    72.         if (position == 0) {  
    73.             return RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM;  
    74.         } else {  
    75.             return RecycleViewWithHead.NORMAL_RECYCLER_VIEW_ITEM;  
    76.         }  
    77.     }  
    78. }  
    import android.content.Context;
    import android.support.v7.widget.RecyclerView;
    import android.support.v7.widget.RecyclerView.ViewHolder;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    import android.widget.Toast;
    
    public class MyRecycleAdapter extends
            RecyclerView.Adapter<MyRecycleAdapterHolder> {
    
        private View headView;
        private Context mContext;
        private int count;
    
        MyRecycleAdapter(Context mContext, int count) {
            this.count = count;
            this.mContext = mContext;
        }
    
        /**
         * 设置数据源总的条目
         */
        @Override
        public int getItemCount() {
            //返回条目数加头布局个数
            return count + 1;
        }
    
        @Override
        public void onBindViewHolder(MyRecycleAdapterHolder holder,
                final int position) {
            int itemViewType = getItemViewType(position);
            // 头部
            if (itemViewType == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {
                return;
            } else if (itemViewType == RecycleViewWithHead.NORMAL_RECYCLER_VIEW_ITEM) {//普通条目
                holder.iv_item_icon.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(mContext, (position - 1) + "", 0).show();
                    }
                });
            }
    
        }
    
        @Override
        public MyRecycleAdapterHolder onCreateViewHolder(ViewGroup parent,
                int viewType) {
            View root = null;
            if (viewType == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {
                root = headView;
            } else {
                root = LayoutInflater.from(mContext).inflate(R.layout.item, parent,
                        false);
            }
            return new MyRecycleAdapterHolder(root, viewType);
        }
    
        /**
         * 添加自定义头部
         */
        public void addHeadView(View view) {
            this.headView = view;
        }
    
        @Override
        public int getItemViewType(int position) {
    
            if (position == 0) {
                return RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM;
            } else {
                return RecycleViewWithHead.NORMAL_RECYCLER_VIEW_ITEM;
            }
        }
    }
    


    普通条目的布局文件item.xml

    1. <?xml version=“1.0” encoding=“utf-8”?>  
    2. <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”  
    3.     android:id=“@+id/ll_list”  
    4.     android:layout_width=“wrap_content”  
    5.     android:layout_height=“wrap_content”  
    6.     android:layout_marginLeft=“2dp”  
    7.     android:layout_marginRight=“2dp”  
    8.     android:layout_marginTop=“5dp”  
    9.     android:orientation=“vertical” >  
    10.   
    11.     <ImageView  
    12.         android:id=“@+id/iv_item_icon”  
    13.         android:layout_width=“wrap_content”  
    14.         android:layout_height=“wrap_content”  
    15.         android:src=“@drawable/item” />  
    16.   
    17.     <TextView  
    18.         android:id=“@+id/tv_item”  
    19.         android:layout_width=“wrap_content”  
    20.         android:layout_height=“wrap_content”  
    21.         android:layout_gravity=“center_horizontal”  
    22.         android:layout_marginTop=“5dp”  
    23.         android:text=“这是一只熊猫” />  
    24.   
    25. </LinearLayout>  
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ll_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="2dp"
        android:layout_marginTop="5dp"
        android:orientation="vertical" >
    
        <ImageView
            android:id="@+id/iv_item_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/item" />
    
        <TextView
            android:id="@+id/tv_item"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="5dp"
            android:text="这是一只熊猫" />
    
    </LinearLayout>



    普通条目的ViewHolder

    1. import android.support.v7.widget.RecyclerView;  
    2. import android.view.View;  
    3. import android.widget.ImageView;  
    4. import android.widget.TextView;  
    5.   
    6. public class MyRecycleAdapterHolder extends RecyclerView.ViewHolder{  
    7.       
    8.     public ImageView iv_item_icon;  
    9.     public TextView tv_item;  
    10.     public MyRecycleAdapterHolder(View itemView) {  
    11.         super(itemView);  
    12.     }  
    13.     public MyRecycleAdapterHolder(View itemView,int viewType) {  
    14.         super(itemView);  
    15.         initView(itemView,viewType);  
    16.     }  
    17.     private void initView(View itemView, int viewType) {  
    18.         iv_item_icon = (ImageView) itemView.findViewById(R.id.iv_item_icon);  
    19.         tv_item = (TextView) itemView.findViewById(R.id.tv_item);  
    20.     }  
    21.   
    22. }  
    import android.support.v7.widget.RecyclerView;
    import android.view.View;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public class MyRecycleAdapterHolder extends RecyclerView.ViewHolder{
    
        public ImageView iv_item_icon;
        public TextView tv_item;
        public MyRecycleAdapterHolder(View itemView) {
            super(itemView);
        }
        public MyRecycleAdapterHolder(View itemView,int viewType) {
            super(itemView);
            initView(itemView,viewType);
        }
        private void initView(View itemView, int viewType) {
            iv_item_icon = (ImageView) itemView.findViewById(R.id.iv_item_icon);
            tv_item = (TextView) itemView.findViewById(R.id.tv_item);
        }
    
    }
    

    效果图:




    还有一种情况类似于淘宝的商品展示我们可以切换每行显示的数量,其实也很简单

    先看下要实现的效果:


    我先说下大致的实现思路:

    1.给adapter设置一个当前显示多行还是单行的标记。

    2.每次切换视图时重置标记,并重置RecycleView的LayoutManager。

    3.调用adapter.notifyItemRangeChanged(2, adapter.getItemCount());(第一个参数是动画开始的位置索引)

    好了再来看下RecycleViewWithHead.java

    1. import com.example.myrecycleviewdemo.adapter.MyRecycleAdapter;  
    2. import android.app.Activity;  
    3. import android.os.Bundle;  
    4. import android.support.v7.widget.GridLayoutManager;  
    5. import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;  
    6. import android.support.v7.widget.RecyclerView;  
    7. import android.view.View;  
    8. import android.view.View.OnClickListener;  
    9. import android.widget.ImageView;  
    10.   
    11. public class RecycleViewWithHead extends Activity implements OnClickListener {  
    12.   
    13.     private RecyclerView rcv;  
    14.     // 当前的条目是recyclerView的头布局  
    15.     public static final int HEADER_RECYCLER_VIEW_ITEM = 0;  
    16.     // 当前的条目是普通recyclerView的条目  
    17.     public static final int NORMAL_RECYCLER_VIEW_ITEM = 1;  
    18.     // 一行显示一个  
    19.     public static final int RECYCLER_VIEW_ITEM_SINGLE = 3;  
    20.     // 一行显示两个  
    21.     public static final int RECYCLER_VIEW_ITEM_DOUBLE = 4;  
    22.     private ImageView iv_switch;// 视图转换  
    23.     private MyRecycleAdapter adapter;  
    24.     private GridLayoutManager manager;  
    25.   
    26.     @Override  
    27.     protected void onCreate(Bundle savedInstanceState) {  
    28.         // TODO Auto-generated method stub  
    29.         super.onCreate(savedInstanceState);  
    30.         setContentView(R.layout.activity_recycle);  
    31.         rcv = (RecyclerView) findViewById(R.id.rcv);  
    32.         iv_switch = (ImageView) findViewById(R.id.iv_switch);  
    33.         iv_switch.setOnClickListener(this);  
    34.         manager = new GridLayoutManager(this2);  
    35.         // 设置布局管理一条数据占用几行,如果是头布局则头布局自己占用一行  
    36.         manager.setSpanSizeLookup(new SpanSizeLookup() {  
    37.             @Override  
    38.             public int getSpanSize(int postion) {  
    39.                 if (postion == 0) {  
    40.                     return 2;  
    41.                 } else {  
    42.                     return 1;  
    43.                 }  
    44.             }  
    45.         });  
    46.         rcv.setLayoutManager(manager);  
    47.         adapter = new MyRecycleAdapter(RecycleViewWithHead.this20);  
    48.         View view = View.inflate(this, R.layout.head, null);  
    49.         // 设置当前ViewType  
    50.         adapter.setSpanSize(RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE);  
    51.         adapter.addHeadView(view);  
    52.         rcv.setAdapter(adapter);  
    53.     }  
    54.   
    55.     @Override  
    56.     public void onClick(View v) {  
    57.         switch (v.getId()) {  
    58.         case R.id.iv_switch:  
    59.             changeRecycleViewList();  
    60.             break;  
    61.   
    62.         default:  
    63.             break;  
    64.         }  
    65.   
    66.     }  
    67.   
    68.     /** 
    69.      * 改变RecycleView的显示列数 
    70.      */  
    71.     private void changeRecycleViewList() {  
    72.         if (adapter != null) {  
    73.             int spanSize = adapter.getSpanSize();  
    74.             // 当前一行显示一列  
    75.             if (spanSize == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE) {  
    76.                 manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {  
    77.                     @Override  
    78.                     public int getSpanSize(int position) {  
    79.                         if (adapter.getItemViewType(position) == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {  
    80.                             return 2;  
    81.                         } else {  
    82.                             return 1;  
    83.   
    84.                         }  
    85.                     }  
    86.                 });  
    87.                 adapter.setSpanSize(RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE);  
    88.             }  
    89.             // 当前一行显示两列  
    90.             else if (spanSize == RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE) {  
    91.                 manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {  
    92.                     @Override  
    93.                     public int getSpanSize(int position) {  
    94.                         if (adapter.getItemViewType(position) == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {  
    95.                             return 2;  
    96.                         } else {  
    97.                             return 2;  
    98.                         }  
    99.                     }  
    100.                 });  
    101.                 adapter.setSpanSize(RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE);  
    102.             }  
    103.             // 第一个参数是动画开始的位置索引  
    104.             adapter.notifyItemRangeChanged(2, adapter.getItemCount());  
    105.         }  
    106.     }  
    107. }  
    import com.example.myrecycleviewdemo.adapter.MyRecycleAdapter;
    import android.app.Activity;
    import android.os.Bundle;
    import android.support.v7.widget.GridLayoutManager;
    import android.support.v7.widget.GridLayoutManager.SpanSizeLookup;
    import android.support.v7.widget.RecyclerView;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ImageView;
    
    public class RecycleViewWithHead extends Activity implements OnClickListener {
    
        private RecyclerView rcv;
        // 当前的条目是recyclerView的头布局
        public static final int HEADER_RECYCLER_VIEW_ITEM = 0;
        // 当前的条目是普通recyclerView的条目
        public static final int NORMAL_RECYCLER_VIEW_ITEM = 1;
        // 一行显示一个
        public static final int RECYCLER_VIEW_ITEM_SINGLE = 3;
        // 一行显示两个
        public static final int RECYCLER_VIEW_ITEM_DOUBLE = 4;
        private ImageView iv_switch;// 视图转换
        private MyRecycleAdapter adapter;
        private GridLayoutManager manager;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_recycle);
            rcv = (RecyclerView) findViewById(R.id.rcv);
            iv_switch = (ImageView) findViewById(R.id.iv_switch);
            iv_switch.setOnClickListener(this);
            manager = new GridLayoutManager(this, 2);
            // 设置布局管理一条数据占用几行,如果是头布局则头布局自己占用一行
            manager.setSpanSizeLookup(new SpanSizeLookup() {
                @Override
                public int getSpanSize(int postion) {
                    if (postion == 0) {
                        return 2;
                    } else {
                        return 1;
                    }
                }
            });
            rcv.setLayoutManager(manager);
            adapter = new MyRecycleAdapter(RecycleViewWithHead.this, 20);
            View view = View.inflate(this, R.layout.head, null);
            // 设置当前ViewType
            adapter.setSpanSize(RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE);
            adapter.addHeadView(view);
            rcv.setAdapter(adapter);
        }
    
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.iv_switch:
                changeRecycleViewList();
                break;
    
            default:
                break;
            }
    
        }
    
        /**
         * 改变RecycleView的显示列数
         */
        private void changeRecycleViewList() {
            if (adapter != null) {
                int spanSize = adapter.getSpanSize();
                // 当前一行显示一列
                if (spanSize == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE) {
                    manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                        @Override
                        public int getSpanSize(int position) {
                            if (adapter.getItemViewType(position) == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {
                                return 2;
                            } else {
                                return 1;
    
                            }
                        }
                    });
                    adapter.setSpanSize(RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE);
                }
                // 当前一行显示两列
                else if (spanSize == RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE) {
                    manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                        @Override
                        public int getSpanSize(int position) {
                            if (adapter.getItemViewType(position) == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {
                                return 2;
                            } else {
                                return 2;
                            }
                        }
                    });
                    adapter.setSpanSize(RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE);
                }
                // 第一个参数是动画开始的位置索引
                adapter.notifyItemRangeChanged(2, adapter.getItemCount());
            }
        }
    }


    布局文件activity_recycle.xml

    1. <RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”  
    2.     xmlns:tools=“http://schemas.android.com/tools”  
    3.     android:layout_width=“match_parent”  
    4.     android:layout_height=“match_parent”>  
    5.   
    6.     <android.support.v7.widget.RecyclerView  
    7.         android:id=“@+id/rcv”  
    8.         android:layout_width=“match_parent”  
    9.         android:layout_height=“wrap_content” />  
    10.       
    11.     <ImageView   
    12.         android:id=“@+id/iv_switch”  
    13.         android:layout_width=“wrap_content”  
    14.         android:layout_height=“wrap_content”  
    15.         android:layout_alignParentTop=“true”  
    16.         android:layout_alignParentRight=“true”  
    17.         android:layout_margin=“20dp”  
    18.         android:src=“@drawable/more”  
    19.         />  
    20.   
    21. </RelativeLayout>  
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rcv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    
        <ImageView 
            android:id="@+id/iv_switch"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_margin="20dp"
            android:src="@drawable/more"
            />
    
    </RelativeLayout>


    适配器MyRecycleAdapter.java

    1. import com.example.myrecycleviewdemo.R;  
    2. import com.example.myrecycleviewdemo.RecycleViewWithHead;  
    3. import com.example.myrecycleviewdemo.R.layout;  
    4. import android.content.Context;  
    5. import android.support.v7.widget.RecyclerView;  
    6. import android.support.v7.widget.RecyclerView.ViewHolder;  
    7. import android.view.LayoutInflater;  
    8. import android.view.View;  
    9. import android.view.View.OnClickListener;  
    10. import android.view.ViewGroup;  
    11. import android.widget.Toast;  
    12.   
    13. public class MyRecycleAdapter extends  
    14.         RecyclerView.Adapter<MyRecycleAdapterHolder> {  
    15.   
    16.     public View headView;  
    17.     public Context mContext;  
    18.     public int count;  
    19.     private int spanSize;// 当前每行显示几列  
    20.   
    21.     public MyRecycleAdapter(Context mContext, int count) {  
    22.         this.count = count;  
    23.         this.mContext = mContext;  
    24.     }  
    25.   
    26.     /** 
    27.      * 设置数据源总的条目 
    28.      */  
    29.     @Override  
    30.     public int getItemCount() {  
    31.         // 返回条目数加头布局个数  
    32.         return count + 1;  
    33.     }  
    34.   
    35.     @Override  
    36.     public void onBindViewHolder(MyRecycleAdapterHolder holder,  
    37.             final int position) {  
    38.         int itemViewType = getItemViewType(position);  
    39.         // 头部  
    40.         if (itemViewType == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {  
    41.             return;  
    42.         } else {// 普通条目  
    43.             if (itemViewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE) {// 一行两列视图  
    44.                 holder.iv_item_icon.setOnClickListener(new OnClickListener() {  
    45.                     @Override  
    46.                     public void onClick(View v) {  
    47.                         Toast.makeText(mContext, ”2列,” + (position - 1) + “”0)  
    48.                                 .show();  
    49.                     }  
    50.                 });  
    51.             } else if (itemViewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE) {// 一行一列视图  
    52.                 holder.iv_item_icon_single.setOnClickListener(new OnClickListener() {  
    53.                     @Override  
    54.                     public void onClick(View v) {  
    55.                         Toast.makeText(mContext,”单列,” + (position - 1) + “”0).show();  
    56.                     }  
    57.                 });  
    58.             }  
    59.         }  
    60.     }  
    61.   
    62.     @Override  
    63.     public MyRecycleAdapterHolder onCreateViewHolder(ViewGroup parent,  
    64.             int viewType) {  
    65.         View root = null;  
    66.         // 头部  
    67.         if (viewType == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {  
    68.             root = headView;  
    69.         } else {// 普通条目  
    70.             /** 一行显示一条 */  
    71.             if (viewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE) {  
    72.                 root = LayoutInflater.from(mContext).inflate(R.layout.item_single, parent, false);  
    73.             }  
    74.             /** 一行显示两条 */  
    75.             else {  
    76.                 root = LayoutInflater.from(mContext).inflate(R.layout.item_double, parent, false);  
    77.             }  
    78.         }  
    79.         return new MyRecycleAdapterHolder(root, viewType);  
    80.     }  
    81.   
    82.     /** 
    83.      * 添加自定义头部 
    84.      */  
    85.     public void addHeadView(View view) {  
    86.         this.headView = view;  
    87.     }  
    88.   
    89.     @Override  
    90.     public int getItemViewType(int position) {  
    91.   
    92.         if (position == 0) {  
    93.             return RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM;  
    94.         } else {  
    95.             /** 一行显示一条 */  
    96.             if (spanSize == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE) {  
    97.                 return RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE;  
    98.                 /** 一行显示两条 */  
    99.             } else {  
    100.                 return RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE;  
    101.             }  
    102.         }  
    103.     }  
    104.   
    105.     public int getSpanSize() {  
    106.         return spanSize;  
    107.     }  
    108.   
    109.     public void setSpanSize(int spanSize) {  
    110.         this.spanSize = spanSize;  
    111.     }  
    112. }  
    import com.example.myrecycleviewdemo.R;
    import com.example.myrecycleviewdemo.RecycleViewWithHead;
    import com.example.myrecycleviewdemo.R.layout;
    import android.content.Context;
    import android.support.v7.widget.RecyclerView;
    import android.support.v7.widget.RecyclerView.ViewHolder;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    import android.widget.Toast;
    
    public class MyRecycleAdapter extends
            RecyclerView.Adapter<MyRecycleAdapterHolder> {
    
        public View headView;
        public Context mContext;
        public int count;
        private int spanSize;// 当前每行显示几列
    
        public MyRecycleAdapter(Context mContext, int count) {
            this.count = count;
            this.mContext = mContext;
        }
    
        /**
         * 设置数据源总的条目
         */
        @Override
        public int getItemCount() {
            // 返回条目数加头布局个数
            return count + 1;
        }
    
        @Override
        public void onBindViewHolder(MyRecycleAdapterHolder holder,
                final int position) {
            int itemViewType = getItemViewType(position);
            // 头部
            if (itemViewType == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {
                return;
            } else {// 普通条目
                if (itemViewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE) {// 一行两列视图
                    holder.iv_item_icon.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Toast.makeText(mContext, "2列," + (position - 1) + "", 0)
                                    .show();
                        }
                    });
                } else if (itemViewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE) {// 一行一列视图
                    holder.iv_item_icon_single.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Toast.makeText(mContext,"单列," + (position - 1) + "", 0).show();
                        }
                    });
                }
            }
        }
    
        @Override
        public MyRecycleAdapterHolder onCreateViewHolder(ViewGroup parent,
                int viewType) {
            View root = null;
            // 头部
            if (viewType == RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM) {
                root = headView;
            } else {// 普通条目
                /** 一行显示一条 */
                if (viewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE) {
                    root = LayoutInflater.from(mContext).inflate(R.layout.item_single, parent, false);
                }
                /** 一行显示两条 */
                else {
                    root = LayoutInflater.from(mContext).inflate(R.layout.item_double, parent, false);
                }
            }
            return new MyRecycleAdapterHolder(root, viewType);
        }
    
        /**
         * 添加自定义头部
         */
        public void addHeadView(View view) {
            this.headView = view;
        }
    
        @Override
        public int getItemViewType(int position) {
    
            if (position == 0) {
                return RecycleViewWithHead.HEADER_RECYCLER_VIEW_ITEM;
            } else {
                /** 一行显示一条 */
                if (spanSize == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE) {
                    return RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE;
                    /** 一行显示两条 */
                } else {
                    return RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE;
                }
            }
        }
    
        public int getSpanSize() {
            return spanSize;
        }
    
        public void setSpanSize(int spanSize) {
            this.spanSize = spanSize;
        }
    }
    


    普通条目的ViewHolder

    1. import com.example.myrecycleviewdemo.R;  
    2. import com.example.myrecycleviewdemo.R.id;  
    3. import com.example.myrecycleviewdemo.RecycleViewWithHead;  
    4. import android.support.v7.widget.RecyclerView;  
    5. import android.view.View;  
    6. import android.widget.ImageView;  
    7. import android.widget.TextView;  
    8.   
    9. public class MyRecycleAdapterHolder extends RecyclerView.ViewHolder{  
    10.     //一行两列视图  
    11.     public ImageView iv_item_icon;  
    12.     public TextView tv_item;  
    13.       
    14.     //一行一列视图  
    15.     public ImageView iv_item_icon_single;  
    16.     public TextView tv_item_single;  
    17.       
    18.     public MyRecycleAdapterHolder(View itemView) {  
    19.         super(itemView);  
    20.     }  
    21.     public MyRecycleAdapterHolder(View itemView,int viewType) {  
    22.         super(itemView);  
    23.         initView(itemView,viewType);  
    24.     }  
    25.     private void initView(View itemView, int viewType) {  
    26.         if(viewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE){  
    27.             iv_item_icon = (ImageView) itemView.findViewById(R.id.iv_item_icon);  
    28.             tv_item = (TextView) itemView.findViewById(R.id.tv_item);  
    29.         }else if(viewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE){  
    30.             iv_item_icon_single = (ImageView) itemView.findViewById(R.id.iv_item_icon_single);  
    31.             tv_item_single = (TextView) itemView.findViewById(R.id.tv_item_single);  
    32.         }  
    33.     }  
    34. }  
    import com.example.myrecycleviewdemo.R;
    import com.example.myrecycleviewdemo.R.id;
    import com.example.myrecycleviewdemo.RecycleViewWithHead;
    import android.support.v7.widget.RecyclerView;
    import android.view.View;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public class MyRecycleAdapterHolder extends RecyclerView.ViewHolder{
        //一行两列视图
        public ImageView iv_item_icon;
        public TextView tv_item;
    
        //一行一列视图
        public ImageView iv_item_icon_single;
        public TextView tv_item_single;
    
        public MyRecycleAdapterHolder(View itemView) {
            super(itemView);
        }
        public MyRecycleAdapterHolder(View itemView,int viewType) {
            super(itemView);
            initView(itemView,viewType);
        }
        private void initView(View itemView, int viewType) {
            if(viewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_DOUBLE){
                iv_item_icon = (ImageView) itemView.findViewById(R.id.iv_item_icon);
                tv_item = (TextView) itemView.findViewById(R.id.tv_item);
            }else if(viewType == RecycleViewWithHead.RECYCLER_VIEW_ITEM_SINGLE){
                iv_item_icon_single = (ImageView) itemView.findViewById(R.id.iv_item_icon_single);
                tv_item_single = (TextView) itemView.findViewById(R.id.tv_item_single);
            }
        }
    }
    

    头布局文件head.xm没有任何变化

    条目的布局拆分为2个item_double.xml和item_single.xml

    item_double.xml和之前的item.xml一样。


    item_single.xml

    1. <?xml version=“1.0” encoding=“utf-8”?>  
    2. <LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android”  
    3.     android:id=“@+id/ll_list”  
    4.     android:layout_width=“wrap_content”  
    5.     android:layout_height=“wrap_content”  
    6.     android:layout_marginLeft=“2dp”  
    7.     android:layout_marginRight=“2dp”  
    8.     android:layout_marginTop=“5dp”  
    9.     android:orientation=“horizontal” >  
    10.   
    11.     <ImageView  
    12.         android:id=“@+id/iv_item_icon_single”  
    13.         android:layout_width=“wrap_content”  
    14.         android:layout_height=“wrap_content”  
    15.         android:src=“@drawable/item” />  
    16.   
    17.     <TextView  
    18.         android:id=“@+id/tv_item_single”  
    19.         android:layout_width=“wrap_content”  
    20.         android:layout_height=“wrap_content”  
    21.         android:layout_gravity=“center_vertical”  
    22.         android:layout_marginTop=“5dp”  
    23.         android:text=“这是一只熊猫” />  
    24.   
    25. </LinearLayout>  
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ll_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="2dp"
        android:layout_marginRight="2dp"
        android:layout_marginTop="5dp"
        android:orientation="horizontal" >
    
        <ImageView
            android:id="@+id/iv_item_icon_single"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/item" />
    
        <TextView
            android:id="@+id/tv_item_single"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginTop="5dp"
            android:text="这是一只熊猫" />
    
    </LinearLayout>


    源码地址:http://download.csdn.NET/detail/linder_qzy/9491370



    展开全文
  • <p>I have a table that logs invalid user login attempts. Every time an invalid attempt is made, the username, user IP, user email and time/date is stored in the database. <p>What I'd like to do ...
  • 列表枚举摘要 用法: ListEnumAbstract . list ( MyEnumAbtract ); @ :enum abstract MyEnumAbstract ( String ) { var A = ' a ' ; var B = ' b ' ; var C = ' c ' ; }
  • RT, 有表test如下 ID Name Score 1 Lily 80 2 Jim 90 3 Jim 99 4 Lucy 85 5 Lily 100 Lily 与 Jim 有相同的, 我要查出 Lily 和 Jim 的那几条怎么查?
  • <p>We have a table with multiple attributes, such as: <p>TABLE_ATTRIBUTES ID, Color, Size, Weight 111, Red, XL null 112, null, SM 10 </p> ...<p>I want to build a method inside my ...
  • <p>I have the following relations between my models <pre><code>Program hasMany Classroom Classroom belongsTo Program </code></pre> <p>What I am trying to achieve is to display all the classrooms...
  • <p>How can I make it so when an entry is created in a table, one of the columns <code>unique_id</code> automatically gets filled with a randomly generated integer? Can this be done straight from ...
  • <p>I have column called 'last updated' of this format: 2009-10-13 09:20:30 and I want to select all entries in the column that have a date that is within the last 7 days of the time the query is ...
  • 在迭代ZIP压缩包的条目时,我检查了这个条目是否是一个文件并且是否匹配一个给定的字段(为了简单,直接把匹配字段硬编码在代码中了),然后利用一个给定的比较器,对这些条目按照大小进行了排序。 为ZIP压缩包...
  • <p>I want to delete all duplicate entries in my mysql database. <p>I found a lot of solutions in the web but in every case the query worked only when you are looking up for 1 column. ...
  • <p>I'm creating a database for the first time! The goal is to have a database for users. I'm using PHPMyAdmin on my localhost (XAMPP) to set it up.... <p>This is pretty straightforward for things ...
  • ... <p>What might be causing this problem? I am suspecting it is whatever sets the $col_class to set the x1 ~ xN, but I cannot find the source of this variable. <p>Here is the code: ...
  • <p>I have another Problem <p>I just can show you this on an example: <p>I got a Table called "myTable" with 7 entries <pre><code>myTable | id | user_id | ...<p>Now i want to list just 3 entries of...
  • 今天部署数据库,实例建好了,建库的时候,一直卡着不动,于是我kill -9杀死了建库进程。然后我手动rm-rf删掉了物理库,于是出现了db2 drop db tsmdb无法删除的情况,db2 list db directory能显示出来。...
  • 这段 sql 是通过给每组数据进行分组后给其添加了一数据。 参考了一篇别人的文章,原文是采用了 set 定义变量, 和case 因为set 所以会有个问题并行的问题,所以这里采用了 (SELECT @order_num:= '') F1, ...
  • <p>I have a table with multiple columns in it, one of which, labeled <code>'ID', contains a unique number.... such as: <code>SELECT * FROM spotzz WHERE ID IN (465, 732, 219)</code> or something along...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,207
精华内容 882
关键字:

列条目