• 实现IOS圆角风格的列表ListView


    这段代码目前已经加在我的一个jar包androidkit中,还没发布。 
    适用于android1.6以上,不依赖其他jar包 

    使用时不需要继承这里的RoundListAdapter。只需要在你实现了ListAdapter的类中,传入一个RoundParams的对象,并在getView方法返回前调用这里RoundListAdapter类提供的静态方法。 
    RoundListAdapter.setItemBackground(position, switcherView, mParams, 
    getCount()); 

    1. [代码]     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    /*
     * @(#)RoundListAdapter.java               Project:com.sinaapp.msdxblog.androidkit
     * Date:2012-12-6
     *
     * Copyright (c) 2011 CFuture09, Institute of Software,
     * Guangdong Ocean University, Zhanjiang, GuangDong, China.
     * All rights reserved.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     *  you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *     http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    package com.lurencun.cfuture09.androidkit.widget.roundlist;
     
    import android.view.View;
    import android.widget.ListAdapter;
     
    /**
     * @author Geek_Soledad (66704238@51uc.com)
     */
    public abstract class RoundListAdapter implements ListAdapter {
        /**
         * 圆角ListView的参数类。定义了顶部背景,底部背景,中间背景及单独一个时的背景。
         *
         * @author msdx
         *
         */
        public static class RoundParams {
            public int topResid;
            public int middleResid;
            public int bottomResid;
            public int lonelyResid;
     
            public RoundParams(int topResid, int middleReside, int bottomResid,
                    int lonelyResid) {
                this.topResid = topResid;
                this.middleResid = middleReside;
                this.bottomResid = bottomResid;
                this.lonelyResid = lonelyResid;
            }
        }
     
        public static void setItemBackground(int position, View item,
                final RoundParams mParams, final int count) {
            if (count == 1) {
                item.setBackgroundResource(mParams.lonelyResid);
            } else if (position > 0 && position < count - 1) {
                item.setBackgroundResource(mParams.middleResid);
            } else if (position == 0) {
                item.setBackgroundResource(mParams.topResid);
            } else {
                item.setBackgroundResource(mParams.bottomResid);
            }
        }
    }

    2. [代码]使用示例     悦德财富“https://www.yuedecaifu.com”

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    /* 
     * @(#)LocalAdapter.java              Project:RTKSETTINGS 
     * Date:2013-1-9 
     
     * Copyright (c) 2013 Geek_Soledad. 
     * All rights reserved. 
     
     * Licensed under the Apache License, Version 2.0 (the "License"); 
     *  you may not use this file except in compliance with the License. 
     * You may obtain a copy of the License at 
     
     *     http://www.apache.org/licenses/LICENSE-2.0 
     
     * Unless required by applicable law or agreed to in writing, software 
     * distributed under the License is distributed on an "AS IS" BASIS, 
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
     * See the License for the specific language governing permissions and 
     * limitations under the License. 
     */
    package com.realtek.msdx.rtksettings.view;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import android.app.TvManager;
    import android.content.Context;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
     
    import com.lurencun.cfuture09.androidkit.widget.roundlist.RoundListAdapter;
    import com.lurencun.cfuture09.androidkit.widget.roundlist.RoundListAdapter.RoundParams;
    import com.realtek.msdx.rtksettings.activity.MainActivity;
    import com.realtek.msdx.rtksettings.bean.LocalSettingsBean;
     
    /**
     * @author Geek_Soledad (msdx.android@tom.com)
     */
    public class LocalAdapter extends BaseAdapter {
     
        private RoundParams mParams;
        private Context mContext;
     
        public LocalAdapter(Context context, RoundParams params) {
            super();
            mContext = context;
            mParams = params;
        }
     
        @Override
        public int getCount() {
            return 5;
        }
     
        @Override
        public Object getItem(int position) {
            return position;
        }
     
        @Override
        public long getItemId(int position) {
            return position;
        }
     
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // 在这里创建view,
            //SwitcherTextView view = new SwitcherTextView(mContext);
            // 然后在返回view前进行调用
            RoundListAdapter.setItemBackground(position, view, mParams,
                    getCount());
            return view;
        }
    }
  • 相关阅读:
    springboot p6spy 打印完整sql
    mybatis报Invalid bound statement (not found) 分析
    springboot Actuator健康检查
    springboot idea 配置热加载
    面试加笔试大全
    面试题(二)
    面试题(一)
    AJAX技术简介及入门实例
    Google的AJAX翻译程序,使你快速全球化
    ASP.NET调用javascript脚本的方法总结
  • 原文地址:https://www.cnblogs.com/oceansea/p/5956260.html
Copyright © 2020-2023  润新知