Android基本样式

223 阅读1分钟

1.(1)id命名简单明确,多个单词的要用下滑线隔开。

2.(2) 制作布局页面时,每个控件的id命名需要规范

1.(1)
android:id="@+id/tv_phone_num"`

控件缩写样式:

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

2.TextView优先使用 wrap_content 代码如下:

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

3.设置颜色的时候,尽量设置透明度。代码如下:

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

4.设置背景颜色推荐在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>

5.图片文件的存放路径需要正确,否则图片显示不出来,在res文件夹下创建drawable-xxxhdpi文件包用来存放图片文件,此外图片命名使用.png格式,例如icom.png。

6.插小符号方式 方法一:在drawable下右键——new——Vector Asset——点击Clip Art选择自己需要的符号,在所需控件里输入引用代码,代码如下:

android:drawableRight="@drawable/ic_baseline_chevron_right_24"

方法二:以图片形式命名使用。png格式上传。

android:src="@drawable/icon_arrow"

7.android:text""(冒号里面的内容)可以在value下的string进行添加、添加颜色的在value下的color进行添加,代码如下:

//文字添加:
<string name="title">基本资料</string>
//颜色添加:
 <color name="blue_ff4f61e7">#ff4f61e7</color>

8.单位样式 :

android:android:layout_height="60dp"//高度或宽度距离用dp。
android:testSize"20sp"//单位是sp。