MacLodge's Blogsince 2022
Android

UI设计常用控件

android:layoutwidth 和 android:layoutheight 指定控件的宽度和高度,可选值有三个:matchparent、fillparent、wrapcontent。

TextView

<TextView
    android:id="@+id/first_txetview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
 
    android:gravity="center"
    android:textSize="24sp"
    android:textColor="#00ff00"
 
    android:text="This is first TextView!"
/>

android:layout_width 和 android:layout_height 指定控件的宽度和高度,可选值有三个:match_parent、fill_parent、wrap_content。

match_parent 和 fill_parent 相似,以父布局大小决定控件大小;

wrap_content 以控件内容决定控件大小。

android:gravity 指定文字对齐方式,可选值 top、bottom、right、left、center 等,可以用 | 同时指定多个值。

android:textSize 和 android:textColor 指定文字大小和颜色。

Button

<Button
    android:id="@+id/first_button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
 
    android:textAllCaps="false"
 
    android:text="This is first Button!"
/>

android:textAllCaps="false" 禁用属性,不对英文字母进行大写转换。

EditText

<EditText
    android:id="@+id/editText"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
 
    android:hint="Please input something"
    android:maxLines="2"
/>

android:hint 指定一段提示性文本,当在输入框输入内容时,这段文字消失。

android:maxLines 指定最大显示行数,超过后文本会向上滑动。

Others

android:src 给 ImageView 指定一张图片,用于显示。

android:

署名-非商业性使用-相同方式共享 4.0 国际(CC BY-NC-SA 4.0)
本文可自由转载与修改,但需保留作者署名与出处链接,不得用于商业用途,且衍生作品需以相同方式共享。 转载请注明:MacLodge's Blog · UI设计常用控件
Esc