TextView
在界面上显示一段文本信息。
<?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"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text_view"
android:text="This is TextView"/>
</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"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text_view"
android:gravity="center"
android:text="This is TextView"/>
</LinearLayout>
可以使用‘|’来同时指定gravity的多个参数。
也可以指定文字的大小(textSize,单位sp)和颜色(textColor),颜色可以用取色器去提取自己想要的颜色,然后填入16进制数据就好。
<?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"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/text_view"
android:gravity="center"
android:textSize="20sp"
android:textColor="#00ff00"
android:text="This is TextView"/>
</LinearLayout>
Button
按钮,这是一个非常熟悉的控件,其实Button是继承自TextView,因为同样的你可以在指定Text属性。
<?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"
>
<Button
android:layout_width="wrap_content"