zoukankan      html  css  js  c++  java
  • 今日所学—Android的常用布局管理

    一、线性布局

     

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:gravity="center"
        android:layout_height="match_parent">
    
        <Button
            android:id="@+id/button"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Button" />
    
        <Button
            android:id="@+id/button2"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Button" />
    
        <Button
            android:id="@+id/button3"
            android:layout_weight="1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            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"
        tools:context=".MainActivity"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ImageView
            android:id="@+id/imageView"
            android:visibility="invisible"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@android:drawable/btn_dialog" />
    
        <ImageView
            android:id="@+id/imageView2"
            android:visibility="visible"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:srcCompat="@mipmap/ic_launcher" />
    
        <Button
            android:id="@+id/button"
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </FrameLayout>
    MainActivity.java文件
    package com.example.xianxingbuju;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    
    public class MainActivity extends AppCompatActivity {
        private Button button;
        private ImageView imageView  ,imageView2;
        private  int k;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.zhenbuju);
    
            button=(Button)findViewById(R.id.button);
            imageView=(ImageView)findViewById(R.id.imageView);
            imageView2=(ImageView)findViewById(R.id.imageView2);
    
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(k%2==0){
                        imageView.setVisibility(View.VISIBLE);
                        imageView2.setVisibility(View.INVISIBLE);
                    }else{
                        imageView.setVisibility(View.INVISIBLE);
                        imageView2.setVisibility(View.VISIBLE);
                    }
                    k++;
                }
            });
    
    
        }
    }

    效果:

     三、表格布局

     

     默认值为0,代表第一列

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:stretchColumns="2"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TableRow
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
    
            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
    
            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </TableRow>
    
        <TableRow
    
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <Button
                android:id="@+id/button5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
    
            <Button
                android:id="@+id/button6"
                android:layout_column="2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button" />
        </TableRow>
    </TableLayout>

    效果:

     四、约束布局

  • 相关阅读:
    Jmeter 添加信息头
    Jmeter 添加 计数器
    Jmeter 用户定义的变量的使用
    Jmeter 获取系统时间
    Fiddler抓包工具使用技巧
    使用adb安装apk包到手机上的安装步骤:
    如何验证所使用的电脑Windows系统是正版还是盗版的方法
    VMware 15 虚拟机安装 win 7 操作系统步骤
    MySQL在windows上安装过程
    SecureCRT的下载、安装过程
  • 原文地址:https://www.cnblogs.com/MoooJL/p/12291721.html
Copyright © 2011-2022 走看看