zoukankan      html  css  js  c++  java
  • 安卓学习第三课——常见布局

    1、相对布局

    简单的说,就是通过描述每个组件所在的位置,使用的layout_below等,就是控制组件与组件之间的位置关系。

    2.绝对布局

    就是通过描述他的x,y坐标来确定位置

    3.线性布局

    有两种是水平和竖直对其方式,一般情况下整体会使用线性布局,来排列众多的组件

    3.帧布局

    我感觉就是一层一层的,默认的情况下,多个组件是在同一个位置,所以你需要去修改位置。同时可以选择是否显示。

    这可以用来描述视频播放器暂停键的控制方法。

    代码如下。

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <TextView 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="我是視頻播放器,我在播放文本"
            android:visibility="visible"
            />
        <LinearLayout   
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            >
        <ImageView 
            android:id="@+id/iv"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:src="@drawable/ic_launcher"
            android:visibility="invisible"
            />
        </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >
    
        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="播放" 
            android:onClick="play"/>
    
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="暫停" 
            android:onClick="pause"/>
    </LinearLayout>
    
    </FrameLayout>
    package com.example.layout;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
        public ImageView iv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.frame);
            iv=(ImageView) findViewById(R.id.iv);
        }
        public void play(View ciew){
            iv.setVisibility(View.INVISIBLE);
        }
        public void pause(View ciew){
            iv.setVisibility(View.VISIBLE);
        }
    }

    代码很简单。但是用到了帧布局和相对布局。

    5.网络布局

    这个的作用就是像网格一样的。感觉和java GUI的功能是一样的。

    总结这些布局,可以类比javaGUI中的几种布局类型。

  • 相关阅读:
    在三层开发的DAL层中, 从web.config中读取数据库的连接字符串的方法
    [转]使用 DataAdapter 执行批量更新
    各式各样的 ICONS
    20个“标准的”配色方案
    一款 FORM 框报错提示 Demo
    超漂亮的仿腾讯弹出层效果
    POJ 2192 (DP)
    POJ 2063 (DP)
    POJ 3624 (DP)
    JavaScript技巧集
  • 原文地址:https://www.cnblogs.com/Yvettey-me/p/3842500.html
Copyright © 2011-2022 走看看