Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android编程之线性布局LinearLayout实例简析大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了Android编程之线性布局LinearLayout用法。@L_616_1@给大家供大家参,具体如下:

线性布局(LinearLayout)

可以让它的子元素垂直或水平的方式排成一行(不设置方向的时候认按照垂直方向排列)。

下面示例是在别人基础上修改的main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="@R_450_10107@://scheR_404_11845@as.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >
  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:baselineAligned="false"
    android:layout_weight="1" >
    <LinearLayout
      android:orientation="horizontal"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:layout_weight="1">
      <TextView
        android:text="@String/color_green"
        android:textColor="#ff0000"
        android:BACkground="#00aa00"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>
      <TextView
        android:text="@String/color_blue"
        android:BACkground="#0000aa"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"/>
    </LinearLayout>
    <LinearLayout
       android:orientation="vertical"
       android:layout_width="wrap_content"
       android:layout_height="fill_parent"
       android:layout_weight="1">
       <TextView
         android:text="@String/color_black"
         android:BACkground="#000000"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_weight="1"/>
       <TextView
         android:text="@String/color_yellow"
         android:BACkground="#aaaa00"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_weight="1"/>
       <TextView
         android:text="@String/color_unkNown"
         android:BACkground="#00aaaa"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:layout_weight="1"/>
     </LinearLayout>
  </LinearLayout>
  <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="2">
    <TextView
      android:text="@String/color_red"
      android:gravity="fill_vertical"
      android:BACkground="#aa0000"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_weight="2"/>
    <TextView
      android:text="@String/color_white"
      android:textColor="#ff0000"
      android:BACkground="#ffffff"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_weight="2"/>
  </LinearLayout>
</LinearLayout>

String.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <String name="Hello">Hello World,TestAbsoluteLayoutActivity!</String>
  <String name="app_name">TestAbsoluteLayout</String>
  <String name= "color_red">red</String>
  <String name= "color_green">green</String>
  <String name= "color_blue">blue</String>
  <String name= "color_white">white</String>
  <String name= "color_black">black</String>
  <String name= "color_yellow">yellow</String>
  <String name= "color_unkNown">unkNown</String>
</resources>

效果图如下:

Android编程之线性布局LinearLayout实例简析

常用的属性

android:orientation:可以设置布局的方向
android:gravity:用来控制组件的对齐方式
layout_weight:控制各个组件在布局中的相对大小

更多关于Android编程布局相关内容可查看本站专题:《Android布局layout技巧总结

希望本文所述对大家Android程序设计有所帮助。

大佬总结

以上是大佬教程为你收集整理的Android编程之线性布局LinearLayout实例简析全部内容,希望文章能够帮你解决Android编程之线性布局LinearLayout实例简析所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:线性布局