界面设计

发布时间 2023-04-12 10:36:25作者: idazhi

界面设计

布局管理器

线性布局

<?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">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />
</LinearLayout>

帧布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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" >

    <Button
        android:id="@+id/button7"
        android:layout_width="372dp"
        android:layout_height="300dp"
        android:text="Button1" />

    <Button
        android:id="@+id/button8"
        android:layout_width="175dp"
        android:layout_height="130dp"
        android:text="Button2" />

    <Button
        android:id="@+id/button9"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button3" />
</FrameLayout>

表格布局

<?xml version="1.0" encoding="utf-8"?>
<TableLayout 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" >
    <TableRow>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn1"
            android:text="button1"
            android:textSize="30dp"

            android:layout_x="100dp"
            android:layout_y="50dp"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/btn2"
            android:text="button2"
            android:textSize="20dp"
            android:textColor="#ff1111"
            android:layout_x="100dp"
            android:layout_y="150dp"/>

    </TableRow>

    <TableRow>
    
    <TextView android:text="第一行第0列"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView android:text="第一行第1列"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView android:text="第一行第2列"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    
    </TableRow>


</TableLayout>

相对布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:id="@+id/btn1"
        android:text="button1"
        android:textSize="50dp"
        android:enabled="false"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/btn2"

        android:layout_marginRight="200dp"

        android:text="button2"
        android:textSize="60dp"
        android:background="#1188aa"
        android:enabled="false"/>

    <!--<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv1"
        android:text="textview1"
        android:textSize="50dp"
        android:textColor="#991111"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv2"
        android:text="textview2"
        android:textSize="60dp"
        android:textColor="#119911"/>-->

</RelativeLayout>