线性布局综合案例

来源:互联网 发布:电脑怎么下载淘宝 编辑:程序博客网 时间:2024/05/17 00:06

这里写图片描述


现在我们来分析上图的布局:
首先根标签是线性布局,布局方式是垂直的,在这个布局中又有两个线性布局,上面的是水平布局,下面的是垂直布局,并且每个布局中有两个TextView,且两个TextView居中显示,并且之间存在边距


XML<?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_width="match_parent"        android:layout_height="0dp"        android:layout_weight="1"        android:gravity="center"        android:orientation="horizontal"        android:background="#ff0000">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="#00ffff"            android:text="first"             android:layout_marginRight="10dp"            />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="#00ffff"            android:text="second"            />    </LinearLayout>    <LinearLayout         android:layout_width="match_parent"        android:layout_height="0dp"        android:orientation="vertical"        android:layout_weight="1"        android:gravity="center"        android:background="#ff00ff">        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="#0000ff"            android:text="first"            android:layout_marginBottom="10dp"            />        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="#0000ff"            android:text="second"            />    </LinearLayout></LinearLayout>

这里写图片描述

原创粉丝点击