zoukankan      html  css  js  c++  java
  • android:layout_weight的简单使用

    weight的意思是权重,在此处可以理解为比例。

    <?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">
        <LinearLayout
            android:layout_margin="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#ac1a1a"
                android:text="1"
                android:textSize="50sp">
    
            </TextView>
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#28469e"
                android:text="1"
                android:textSize="50sp">
    
            </TextView>
    
        </LinearLayout>
        <LinearLayout
            android:layout_margin="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#ac1a1a"
                android:text="1/3"
                android:textSize="50sp">
    
            </TextView>
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:background="#28469e"
                android:text="2/3"
                android:textSize="50sp">
    
            </TextView>
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_margin="10dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:background="#ac1a1a"
                android:text="200dp"
                android:textSize="50sp">
    
            </TextView>
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#28469e"
                android:text="剩余的"
                android:textSize="50sp">
    
            </TextView>
    
        </LinearLayout>
    
    </LinearLayout>

    第一个LinearLayout里的两个textview按1:1分配宽度。

    第二个LinearLayout里的两个textview按1:2分配宽度。

    第三个LinearLayout里的两个textview一个是固定宽度,另一个占满剩余的宽度。

    
    
  • 相关阅读:
    将博客部署到k3s中
    docker/docker swarm学习
    windows共享文件夹使用中的问题(SMB协议)
    洛谷P1280 尼克的任务 题解 动态规划/最短路
    CF1B.Spreadsheets(电子表格) 题解 模拟
    洛谷P1595 信封问题 题解 错排问题
    洛谷P1809 过河问题 经典贪心问题
    CF1238E.Keyboard Purchase 题解 状压/子集划分DP
    洛谷P2719 搞笑世界杯 题解 概率DP入门
    Treap(树堆)入门
  • 原文地址:https://www.cnblogs.com/silenceshining/p/5383470.html
Copyright © 2011-2022 走看看