美文网首页
Android的大小的适配问题

Android的大小的适配问题

作者: Charon_Pluto | 来源:发表于2018-06-15 11:15 被阅读27次

在xml中我们一般进行一个textView的书写的时候

<TextView
            android:id="@+id/tx1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="10dp"
            android:text="Hello World!"
            android:textSize="17sp" />

如果你想要动态代码设置的时候也能够存在这样的padding效果和textSize大小

(1)边距

    **需要进行dp转换成px**
    textView2.setPadding(AttrGet.dp2px(10),0,0,0);

(2)文字大小不仅需要sp转换成px还需要getPaint()方法

    textView2.getPaint().setTextSize(AttrGet.sp2px(17));

相关文章

网友评论

      本文标题:Android的大小的适配问题

      本文链接:https://www.haomeiwen.com/subject/weppeftx.html