安卓的常用控件

安卓的常用控件

Testview

<TextView
    android:id="@+id/text_view"
    android:layout_width="match_parent"
    android:Layout_height="wrap_content"
    android:text="This is TextView"/>

android:text指定TextView中的文本显示内容
android:gravity指定文字的对齐方式,可选值为top bottom left right center 等,也可用 | 来指定多个值.center效果等同于 center_vertical | center_horizontal,表示文字在垂直和水平方向都居中对齐
android:textSize 指定文字大小
android:textColor 指定文字颜色

button

<Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:Layout_height="wrap_content"
    android:text="Button"
    android:textAllCaps="false"/>

android:textAllCaps 由于系统会对Button的所有英文字母进行大写转换,该属性设为false就不转换了

EditText

<EditText
    android:id="@+id/edit_text"
    android:layout_width="match_parent"
    android:Layout_height="wrap_content"
    android:hint="Type something here"
    android:maxLines="2"/>

android:hint 属性指定了一段提示文本,当我们输入任何内容,这段文本就会自动消失
android:maxLines 属性指定了EditText最大行数为2行,这样当输入的内容超过两行时,文本就会向上滚动,而EditText不会再继续拉伸.

ImageView

<ImageView
    android:id="@+id/image_view"
    android:layout_width="match_parent"
    android:Layout_height="wrap_content"
    android:src="@drawable/img"/>

android:src 该属性给ImageView指定一张图片,
通过代码指定图片

ProgressBar

<ProgressBar
    android:id="@+id/progress_bar"
    android:layout_width="match_parent"
    android:Layout_height="wrap_content"
    style="?android:attr/progressBarStyleHorizontal"
    android:max="100"/>

style属性可以设置进度条样式
android:max属性设置进度条最大值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值