• Android开发(三) android布局


      这一节我们讲解一下android的UI布局。和我们制作网页一样,也需要为我们手机上的控件进行一下布局,android系统中提供了很多灵活的布局类,比如LinearLayout、RelativeLayout、FrameLayout等等,这里我们简单的介绍一下这三个布局:

      1、RelativeLayout,从字面上可以看出这个是相对布局类。也就是说在这个布局里面的控件的位置都是通过相对位置来计算的。

    RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TextView
    android:id="@+id/login_name"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_marginTop
    ="8dip"
    android:text
    ="User Name:"
    />
    <EditText
    android:id="@+id/txtLoginName"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:layout_toRightOf
    ="@id/login_name"
    android:layout_alignTop
    ="@id/login_name"
    android:layout_marginLeft
    ="40dip"
    android:layout_marginTop
    ="-8dip"
    android:inputType
    ="text"
    />
    <TextView
    android:id="@+id/password"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_below
    ="@id/login_name"
    android:layout_marginTop
    ="80dip"
    android:text
    ="Password:"
    />
    <EditText
    android:id="@+id/txtPwd"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:layout_toRightOf
    ="@id/password"
    android:layout_alignTop
    ="@id/password"
    android:layout_marginLeft
    ="40dip"
    android:layout_marginTop
    ="-8dip"
    android:inputType
    ="text"
    />
    <Button
    android:id="@+id/btnLogin"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_below
    ="@id/password"
    android:layout_marginTop
    ="50dip"
    android:layout_marginLeft
    ="30dip"
    android:text
    ="Login"
    />
    <Button
    android:id="@+id/btnCancel"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_toRightOf
    ="@id/btnLogin"
    android:layout_alignTop
    ="@id/btnLogin"
    android:layout_marginTop
    ="0dip"
    android:layout_marginLeft
    ="30dip"
    android:text
    ="Cancel"
    />
    </RelativeLayout>

    上面代码显示的布局是这样的:



  • 相关阅读:
    Git回退---reset和revert
    XML解析
    SpringBoot学习day01
    Spring boot精要
    JS没有contains方法,可以用indexof实现
    git fetch 取回所有分支(branch)的更新(转)
    idea 设置注释模板
    git退出编辑模式
    git 提交代码到远程分支
    linux下,保存退出vim编辑器(转)
  • 原文地址:https://www.cnblogs.com/bugY/p/2396653.html
Copyright © 2020-2023  润新知