• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > 我的投资3--热门理财,投资3--热门理财

我的投资3--热门理财,投资3--热门理财

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了热门投资理财,我想要理财投资公司,我想投资理财,我要投资理财平台,我想要理财投资信息等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

我的投资3--热门理财,投资3--热门理财


”热门理财”的流式布局的实现

1.自定义流式布局

public class FlowLayout extends ViewGroup {
    public FlowLayout(Context context) {
        super(context);
    }

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

    public FlowLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        int heightSize = MeasureSpec.getSize(heightMeasureSpec);

        //记录当前布局的宽高
        int width = 0;
        int height = 0;

        //记录一行视图的宽度、高度
        int lineWidth = 0;
        int lineHeight = 0;

        //获取在at_most模式下的布局的宽度、高度
        int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childView = getChildAt(i);

            measureChild(childView, widthMeasureSpec, heightMeasureSpec);
            int childWidth = childView.getMeasuredWidth();
            int childHeight = childView.getMeasuredHeight();
            MarginLayoutParams mp = ((MarginLayoutParams) childView.getLayoutParams());
            //表示当前的子视图还可以放在一行上
            if (lineWidth + childWidth + mp.leftMargin + mp.rightMargin < widthSize) {
                lineWidth += childWidth + mp.leftMargin + mp.rightMargin;

                lineHeight = Math.max(lineHeight, childHeight + mp.topMargin + mp.bottomMargin);

            } else {//换行
                width = Math.max(width, lineWidth);
                height += lineHeight;

                //重置
                lineWidth = childWidth + mp.leftMargin + mp.rightMargin;
                lineHeight = childHeight + mp.topMargin + mp.bottomMargin;
            }

            if (i == childCount - 1) {
                width = Math.max(width, lineWidth);
                height += lineHeight;
            }
        }

        Log.e("TAG", "width = " + width + ",height = " + height);
        setMeasuredDimension(widthMode == MeasureSpec.EXACTLY ? widthSize : width, heightMode == MeasureSpec.EXACTLY ? heightSize : height);
    }

    private List<List<View>> allViews = new ArrayList<List<View>>();
    private List<Integer> allHeights = new ArrayList<>();

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        int width = getWidth();
        int childCount = getChildCount();

        int lineWidth = 0;
        int lineHeight = 0;
        List<View> lineViews = new ArrayList<>();

        for (int i = 0; i < childCount; i++) {
            View childView = getChildAt(i);

            int childWidth = childView.getMeasuredWidth();
            int childHeight = childView.getMeasuredHeight();
            MarginLayoutParams mp = (MarginLayoutParams) childView.getLayoutParams();
            //不换行
            if (lineWidth + childWidth + mp.leftMargin + mp.rightMargin < width) {
                lineWidth += childWidth + mp.leftMargin + mp.rightMargin;
                lineViews.add(childView);
                lineHeight = Math.max(lineHeight, childHeight + mp.topMargin + mp.bottomMargin);

            } else {//换行
                allViews.add(lineViews);
                allHeights.add(lineHeight);
                lineViews = new ArrayList<>();
                lineViews.add(childView);

                lineWidth = childWidth + mp.leftMargin + mp.rightMargin;
                lineHeight = childHeight + mp.topMargin + mp.bottomMargin;
            }

            if (i == childCount - 1) {
                allViews.add(lineViews);
                allHeights.add(lineHeight);
            }

        }
        Log.e("TAG", "allViews.size = " + allViews.size() + ",allHeights.size = " + allHeights.size());

        //通过计算每一行的每一个子view的left,top,right,bottom,摆放每一行的每一个子view的位置
        int x = 0;
        int y = 0;

        for (int i = 0; i < allViews.size(); i++) {
            int curLineHeight = allHeights.get(i);
            //当前行的所有子view
            List<View> views = allViews.get(i);
            for (View view : views) {
                int viewWidth = view.getMeasuredWidth();
                int viewHeight = view.getMeasuredHeight();
                MarginLayoutParams mp = (MarginLayoutParams) view.getLayoutParams();
                int lc = x + mp.leftMargin;
                int tc = y + mp.topMargin;
                int rc = lc + viewWidth;
                int bc = tc + viewHeight;
                view.layout(lc, tc, rc, bc);
                x += viewWidth + mp.rightMargin + mp.leftMargin;
            }
            x = 0;
            y += curLineHeight;
        }
    }

    //有了如下的方法,在上面通过child就可以getLayoutParams()
    @Override
    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
        MarginLayoutParams mp = new MarginLayoutParams(getContext(), attrs);
        return mp;
    }
}

2.xml

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

    <com.atguigu.p2p.ui.FlowLayout
        android:id="@+id/flow_hot"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/holo_green_light">
    </com.atguigu.p2p.ui.FlowLayout>

</LinearLayout>

3.ProductHotFragment

public class ProductHotFragment extends BaseFragment {


    @Bind(R.id.flow_layout)
    FlowLayout flowLayout;

    //提供页面要显示的数据
    private String[] datas = new String[]{"新手计划", "乐享活系列90天计划", "钱包", "30天理财计划(加息2%)",
            "林业局投资商业经营与大捞一笔", "中学老师购买车辆", "屌丝下海经商计划", "新西游影视拍",
            "Java培训老师自己周转", "HelloWorld", "C++-C-ObjectC-java", "Android vs ios", "算法与数据结构", "JNI与NDK", "team working"};
    private Random random;

    @Override
    protected RequestParams getParams() {
        return null;
    }

    @Override
    protected String getUrl() {
        return null;
    }

    @Override
    protected void initData(String content) {
        random = new Random();
        //1.动态的创建TextView
        for(int i = 0; i < datas.length; i++) {

            final TextView tv = new TextView(getActivity());

            //设置TextView的属性
            tv.setText(datas[i]);
            tv.setTextSize(UIUtils.dp2Px(10));

            ViewGroup.MarginLayoutParams mp = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
            mp.leftMargin = UIUtils.dp2Px(8);
            mp.rightMargin = UIUtils.dp2Px(8);
            mp.topMargin = UIUtils.dp2Px(8);
            mp.bottomMargin = UIUtils.dp2Px(8);
            tv.setLayoutParams(mp);

            //设置textView的背景
            int red = random.nextInt(211);
            int green = random.nextInt(211);
            int blue = random.nextInt(211);
            //测试一:
//            tv.setBackground(DrawUtils.getDrawable(Color.rgb(red,green,blue),UIUtils.dp2Px(5)));

            //测试二:
            tv.setBackground(DrawUtils.getSelector(DrawUtils.getDrawable(Color.rgb(re



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 我的投资3--热门理财,投资3--热门理财

相关文章

  • 2017-07-22Android-SQLite和SQLiteOpenHelper
  • 2017-05-26【转载】ReactiveX 的理念和特点,转载reactivex理念
  • 2017-05-26nagios分组出图代码实现讲解[1]
  • 2017-05-26Android中View的事件分发机制——Android开发艺术探索笔记
  • 2017-05-26android源码解析之(三)--)HandlerThread
  • 2017-05-26LinearLayout嵌套,linearlayout
  • 2017-05-26精品干货丨APP常用导航框架,干货丨app导航
  • 2017-05-26微信小程序监控,信小程序监控
  • 2017-05-26编译android源码3---ubuntu安装jdk6
  • 2017-05-26AndroidStudio如何快速制作.so

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Android sdk content loader 0%,androidsdk
    • 深入理解 Android 之 View 的绘制流程,androidview
    • svn环境搭建(不同目录、设置不同的权限)
    • FlatBuffers初探,flatbuffers
    • 硅谷社交15--群详情,硅谷社交15--
    • redis使用内存调整及优化
    • Android ShareSDK快速实现分享功能,androidsharesdk
    • Intent(二)隐式调用intent,调用intent
    • Android Studio安装配置、环境搭建详细步骤及基本使用,android安装配置
    • android launchmode 使用场景

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有