使用AndroidAutoLayout遇到的一些问题




 
        //为方便你们使用 直接手敲 可以复制  ̄▽ ̄
        TextView text = (TextView) findViewById(R.id.text);

        //获取LayoutParams,一定要.getLayoutParams()
        //一定要强转为该控件的父容器ClassLayoutParams,
        // 如果转化类型不对 运行会报 类型转化错误,
        // 如果不转或者直接转为ViewGroup.LayoutParams XML中相关参数设置将会无效!!!
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) text.getLayoutParams();
        layoutParams.width = AutoUtils.getPercentWidthSize(300);
        layoutParams.height = AutoUtils.getPercentHeightSize(300);

        int margin = AutoUtils.getPercentHeightSize(20);
        layoutParams.setMargins(margin, margin, margin, margin);


        //设置LayoutParams相关参数后一直要setLayoutParams
        //text.setLayoutParams(layoutParams);
        text.setLayoutParams(new LinearLayout.LayoutParams(layoutParams));
        //如果还想setTextSize  应该讲上面改成这样setLayoutParams(new LinearLayout.LayoutParams(layoutParams))

        //使用这个框架后,TextViewLayout等于null,直接setTextSize无效
        //setTextSize之前一定要有使用setLayoutParams!!!  否则设置无效
        //AndroidAutoLayoutTextSize大小参照屏幕高度设置,使用AutoUtils.getPercentHeightSize
        int textSize = AutoUtils.getPercentHeightSize(100);
        //setTextSize  单位PX
        text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

        //关于setTextSize重点提及,如果只是需要单独设置TextSize,为了方便
//        ViewGroup.LayoutParams params = text.getLayoutParams();
//        if (params instanceof LinearLayout.LayoutParams) {
//            LinearLayout.LayoutParams layoutParams= (LinearLayout.LayoutParams) text.getLayoutParams();
//            text.setLayoutParams(new LinearLayout.LayoutParams(layoutParams));
//        } else if (params instanceof RelativeLayout.LayoutParams) {
//            RelativeLayout.LayoutParams layoutParams= (RelativeLayout.LayoutParams) text.getLayoutParams();
//            text.setLayoutParams(new RelativeLayout.LayoutParams(layoutParams));
//        } else if (params instanceof FrameLayout.LayoutParams) {
//            FrameLayout.LayoutParams layoutParams= (FrameLayout.LayoutParams) text.getLayoutParams();
//            text.setLayoutParams(new FrameLayout.LayoutParams(layoutParams));
//        }else...
//        text. setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);

        int padding = AutoUtils.getPercentHeightSize(20);
        text.setPadding(padding, padding, padding, padding);

        
        //适配adapter中的itemView
        // (因为ListViewReRecyclerViewadapter不同,或者 你使用了其他adapter的框架,不管如何重点是 在ViewHolder创建之后设置 !!!) AutoUtils.auto(itemView);
        
        //这个框架还有其他问题  怎么适配style中的相关参数啊 还有性能问题(到底是重新绘制UI 还是绘制前重新计算)
       // and so on

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值