Android基础控件(EditView、SeekBar等)的使用方法

2019-12-10 18:51:55王振洲
易采站长站为您分析Android基础控件的属性及使用方法,介绍了基础控件有TextView、ImageView、Button、EditView等,感兴趣的小伙伴们可以参考一下  

 android提供了大量的UI控件,本文将介绍TextView、ImageView、Button、EditView、ProgressBar、SeekBar、ScrollView、WebView的使用方法。在介绍各种控件之前,先简单介绍android UI控件最基本的几种属性:

id: id是控件唯一标识符,可通过**findViewById(R.id.*)**操作控件。
layout_width:控件宽度,可设置为match_parent(充满父布局,即让父布局决定当前控件的宽度)、wrap_content(恰好包住里面的内容)、具体值(一般以dp作为单位)。
layout_width:控件高度,可设置为match_parent、wrap_content、具体值。
visibility:可见与否,有三个可选值:visible(可见,不设置该属性为默认值)、invisible(透明,仍在屏幕上占据空间)、gone(不可见,不占据空间)。
1.TextView(文本)

TextView可以说是最简单的控件了。

1.1 基本属性

<!--res/layout/activity_main.xml-->
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">
 
  <TextView
    android:id="@+id/text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:textSize="30sp"
    android:textColor="#334433"
    android:text="@string/app_name"
    />
 
</LinearLayout>

text: text属性即显示出来的文字,@string/app_name表示引用资源文件res/values/strings.xml中的app_name,也可以直接写内容。

<!--res/values/strings.xml-->
<resources>
  <string name="app_name">UIExample</string>
  <string name="title_activity_main">MainActivity</string>
</resources>