//为方便你们使用 直接手敲 可以复制  ̄▽ ̄ TextView text = (TextView) findViewById(R.id.text); //获取LayoutParams,一定要.getLayoutParams() //一定要强转为该控件的父容器Class的LayoutParams, // 如果转化类型不对 运行会报 类型转化错误, // 如果不转或者直接转为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)) //使用这个框架后,TextView中Layout等于null,直接setTextSize无效 //setTextSize之前一定要有使用setLayoutParams!!! 否则设置无效 //AndroidAutoLayout中TextSize大小参照屏幕高度设置,使用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 // (因为ListView和ReRecyclerView的adapter不同,或者 你使用了其他adapter的框架,不管如何重点是 在ViewHolder创建之后设置 !!!) AutoUtils.auto(itemView); //这个框架还有其他问题 怎么适配style中的相关参数啊 还有性能问题(到底是重新绘制UI 还是绘制前重新计算) // and so on