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>
  • 相关阅读:
    mongo连接拒绝10061原因
    python爬取CNKI的期刊
    C语言socket编程
    Linux c time模块函数库
    linux下python3调用c代码或者python3调用c++代码
    stl综合
    linux c调用 mysql代码
    debian系列下c++调用mysql, linux下面安装mysql.h文件
    c++ linux socket编程 c++网络编程
    比较均值分析思路
  • 原文地址:https://www.cnblogs.com/geeksongs/p/10455890.html
Copyright © 2011-2022 走看看