zoukankan      html  css  js  c++  java
  • Android学习第五天

    详解3种基本布局

    LinearLayout又称作线性布局,这个布局会将它所包含的控件在线性方向上依次排列。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 1" />
    <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 2" />
    <Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button 3" />
    </LinearLayout>

     LinearLayout横向排列的效果。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    ...
    </LinearLayout>

    LinearLayout使用ayout_gravity属性对齐的效果。
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:text="Button 1" />
    <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:text="Button 2" />
    <Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:text="Button 3" />
    </LinearLayout>

    RelativeLayout又称作相对布局,它可以通过相对定位的方式让控件出现在布局的任何位置。
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" …>
    <Button …
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Button 1" />
    <Button …
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:text="Button 2" />
    <Button …
    android:layout_centerInParent="true"
    android:text="Button 3" />
    <Button …
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:text="Button 4" />
    <Button …
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Button 5" />
    </RelativeLayout>

    除了相对于父布局定位之外,RelativeLayout还允许相对于控件进行定位。
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" ...>
    <Button ...
    android:layout_centerInParent="true"
    android:text="Button 3" />
    <Button ...
    android:layout_above="@id/button3"
    android:layout_toLeftOf="@id/button3"
    android:text="Button 1" />
    <Button ...
    android:layout_above="@id/button3"
    android:layout_toRightOf="@id/button3"
    android:text="Button 2" />
    <Button ...
    android:layout_below="@id/button3"
    android:layout_toLeftOf="@id/button3"
    android:text="Button 4" />
    <Button ...
    android:layout_below="@id/button3"
    android:layout_toRightOf="@id/button3"
    android:text="Button 5" />
    </RelativeLayout>

  • 相关阅读:
    POJ 1611 The Suspects(并查集)
    POJ 2485 Highways(最小生成树Prim算法)
    POJ 1062 昂贵的聘礼(最短路径Dijkstr的变形)
    SDUT 2374 || HDU 1803Cylinder(计算几何求体积)
    HDU 1804 || SDUT 2375 Deli Deli(简单题)
    POJ 3041 Asteroids(二分图的最大匹配)
    HDU 1802 || SDUT 2373 Black and white painting(规律)
    POJ 1035 Spell checker(字符串简单匹配)
    POJ 3080 Blue Jeans(KMP模式匹配)
    js中反斜杠\的一些研究
  • 原文地址:https://www.cnblogs.com/yongyuandishen/p/14865984.html
Copyright © 2011-2022 走看看