zoukankan      html  css  js  c++  java
  • 安卓开发学习笔记(八):线性布局

    线性布局是Android中较为常用的布局方式,使用LinearLayout标签。线性布局主要有两种形式,一种是水平线性布局,一种是垂直线性布局。需要注意的是Android的线性布局不会换行,当组件一个挨着一个地排列到头之后,剩下的组件将不会被显示出来。

    下表显示了LinearLayout支持的常用XML属性及相关方法的说明。

    LinearLayout 包含的所有子元素都受 LinearLayout.LayoutParams 控制,因此 LinearLayout包含的子元素可以额外指定如如下属性。

    android:layout_gravity:指定该子元素在LinearLayout中的对齐方式。

    android:layout_weight:指定该子元素在LinearLayout中所占的权重。下面我们来看看具体如何进行线性布局:

    一.线性布局的控件在整个控件最高处

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/fruit_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/fruit_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
    //这里用这个将textview写到了整个线性布局的最下面上方
     android:layout_marginLeft="10dp"/> </LinearLayout>

    二.线性布局的控件在整个控件的中间

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/fruit_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/fruit_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
    //这里用这个将textview写到了整个线性布局的最中间
     android:layout_marginLeft="10dp"/> </LinearLayout>

    三.线性布局的控件在整个控件的最下方

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/fruit_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/fruit_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"//这里用这个将textview写到了整个线性布局的最下面
            android:layout_marginLeft="10dp"/>
    
    
    </LinearLayout>
  • 相关阅读:
    http请求类型简介
    关于PLSQL连接报错:ORA-12154:TNS:无法解析指定的连接标识符
    JDK8的安装与配置
    今天新装tomcat遇到黑窗口(startup.bat)启动乱码问题解决!!!
    一个简单的工厂模式(一个接口,多个实现,通过调用条件的不同,分别去调用符合的实现)
    数组(复习)
    java选择结构、循环结构(复习)
    java常用的数据类型,变量和常量,运算符(复习)
    java输入输出,书写规范,运行原理,跨平台原理(复习)
    JAVA基础入门(JDK、eclipse下载安装)
  • 原文地址:https://www.cnblogs.com/geeksongs/p/10455890.html
Copyright © 2011-2022 走看看