zoukankan      html  css  js  c++  java
  • Android布局gravity用法

    在main.xml 或者其他xml 布局文件中布局Button的时候,选择Android:gravity="center_horizontal",意思是Place object in the horizontal center of its container, not changing its size.我们用RelativeLayout 布局,这样可以使不同的组件有对齐的方式。

     

     

     

    [代码] main.xml

    01 <?xml version="1.0" encoding="utf-8"?>
    02 <RelativeLayout xmlns:Android="http://schemas.android.com/apk/res/android"
    03     Android:layout_width="fill_parent"
    04     Android:layout_height="fill_parent">
    05     <TextView Android:id="@+id/gallerytext"
    06         Android:layout_width="fill_parent"
    07         Android:layout_height="wrap_content">
    08     </TextView>
    09     <Gallery Android:id="@+id/gallery"
    10         Android:layout_width="fill_parent"
    11         Android:layout_height="wrap_content">
    12     </Gallery>
    13     <Button Android:id="@+id/btngal"
    14         Android:layout_width="wrap_content"
    15         Android:layout_height="wrap_content"
    16         Android:gravity="center_horizontal"
    17         Android:textSize="20sp"
    18         Android:layout_alignParentBottom="true"
    19         Android:layout_centerHorizontal="true"
    20         Android:text="返回主界面"/>

     

     

    [代码] 简单说明

    1 可以看到Button 与Gallery的对齐方式是居中对齐,也即Button 与Parent居中对齐。
    2 另外,
    3 Android:gravity="CENTER_VERTICAL“:这个是垂直居中对齐
    4 Android:gravity="BOTTOM”:放在容器的底部
    5 Android:gravity="CENTER“ :放在容器的中心

     

  • 相关阅读:
    P6329 【模板】点分树 | 震波
    Luogu P3350 [ZJOI2016]旅行者
    Luogu [ZJOI2015]幻想乡战略游戏
    斐波那契数列简单性质
    Luogu P2056 [ZJOI2007]捉迷藏
    Luogu P4127 [AHOI2009]同类分布
    A funny story in regard to a linux newbie
    Inside the c++ object module 阅读摘要
    java并发编程
    JVM执行引擎总结(读《深入理解JVM》) 早期编译优化 DCE for java
  • 原文地址:https://www.cnblogs.com/thomaskwan/p/2515468.html
Copyright © 2011-2022 走看看