本章主要介绍基本的平常较多使用的控件,包括TextView、EditView、ImageView、Button等。本章将介绍相关控件基本属性的使用,为以后章节的进阶学习提供基础。案例中引用的LinearLayout布局,可先不必深究,后续章节将会详细介绍。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="TextView" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableLeft="@drawable/tupiao" android:gravity="center" android:text="TextView_drawableLeft" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableRight="@drawable/tupiao" android:gravity="center" android:text="TextView_drawableRight" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableTop="@drawable/tupiao" android:gravity="center" android:text="TextView_drawableTop" /> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableBottom="@drawable/tupiao" android:gravity="center" android:text="TextView_drawableBottom" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:text="EditText" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:hint="please input your message! " /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableTop="@drawable/tupiao" android:gravity="center" android:hint="please input your message! " /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableTop="@drawable/tupiao" android:gravity="center" android:text="EditText" /> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:drawableLeft="@drawable/tupiao" android:gravity="center" android:password="true" android:text="EditText" /> </LinearLayout>效果截图:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/image" /> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/background_dark" android:src="@drawable/image" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/button" android:text="Button" /> <ImageButton android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/button_with_text" /> </LinearLayout>
【ALearning】第三章 Android基本常见控件,布布扣,bubuko.com
原文地址:http://blog.csdn.net/mahoking/article/details/37515399