Android布局规范

453 阅读1分钟

分享一些Android布局制作的学习心得

要点一:制作布局页面时,每个控件的id命名需要规范,多个单词需要用_隔开

控件                   缩写
LinearLayout           ll
RelativeLayout         rl
ConstraintLayout       cl
ListView               lv
ScollView              sv
TextView               tv
Button                 btn
ImageView              iv
CheckBox               cb
RadioButton            rb
EditText               et

要点二:TextView优先使用"wrap_content"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

要点三:设置颜色时,尽量设置透明度,例如

#ff333333
android:textColor="@color/black_ff333333"

要点四:设置背景颜色推荐在drawable下创建一个shape.xml文件,文件内容如下

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="30dp"/>
    <solid android:color="#FFE6E6FA"/>
    <padding
        android:bottom="5dp"
        android:top="5dp"
        android:left="10dp"
        android:right="10dp"/>
</shape>

要点五:图片文件的存放路径需要正确,否则图片显示不出来,在res文件夹下创建drawable-xxxhdpi文件包用来存放图片文件,此外图片命名使用.png、.webp以及.jpg格式

要点六:设置样式时推荐使用alt+enter快捷键调出资源框

image.png

image.png

要点七:插入小符号方法:

步骤:在drawable下右键——new——Vector Asset——点击Clip Art选择自己需要的符号,在所需控件里输入引用代码,例如

android:drawableRight="@drawable/ic_baseline_chevron_right_24"