目录

Android UI

布局管理器

1.线性布局(LinearLayout)

常用属性:

例如
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/11_1"
        android:layout_width="200dp"
        android:layout_height="300dp"
        android:orientation="vertical"
        android:background="#000000"
        android:padding="20dp">

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#0000ff"
            android:layout_weight="1"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ff00ff"
            android:layout_weight="1"/>
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#00ff00"
            android:layout_weight="1"/>
    </LinearLayout>

</LinearLayout>

效果:

2.相对布局(RelativeLayout)

常用属性:

例如
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <View
        android:id="@+id/1"
        android:layout_width="200dp"
        android:layout_height="300dp"
        android:background="#300000"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:background="#00ff00"
        android:layout_toLeftOf="@id/1"/>
    <LinearLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentRight="true"
        android:background="#0000ff">

    </LinearLayout>
</RelativeLayout>

效果:

TextView组件

作用:

  • 文字大小、颜色
  • 文字太多显示不下时使用…
  • 文字+icon
  • 中划线、下划线
  • 跑马灯
例如
<?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"
    android:padding="20dp">

    <!--文字显示-->
    <TextView
        android:id="@+id/tv_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello你好"
        android:textColor="#0000ff"
        android:textSize="26sp"/>

    <!--太多时缩略显示-->
    <TextView
        android:id="@+id/tv_2"
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:text="Hello你好"
        android:maxLines="1"
        android:ellipsize="end"
        android:textColor="#00ff00"
        android:textSize="26sp"
        android:layout_marginTop="10dp"/>

    <!--滚动-->
    <TextView
        android:id="@+id/tv_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello你好Hello你好Hello你好Hello你好Hello你好Hello你好"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:textColor="#ff0000"
        android:textSize="26sp"/>

</LinearLayout>

效果:

Button

作用:

  1. 文字大小、颜色
  2. 自定义背景形状
  3. 自定义按压效果
  4. 点击事件