实现button在屏幕居中

要实现button在LinearLayout布注意局屏幕中间居中需要做到两点在linearLayout中设置
android:orientantion 竖屏或者横屏居中
android:gravity 设置内容在layout中的位置
例如:

按键及其居中_第1张图片 image.png

<?xml version="1.0" encoding="utf-8"?>

xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">

android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Anr Demo" />

>

android:orientation

| Constant | Value | Description |
|:---------:|:-------------:|: -----|
|horizontal |0 |Defines an horizontal widget. |
| vertical | 1| Defines a vertical widget.|

android:gravity

Constant Value Description
bottom 50 Push object to the bottom of its container, not changing its size.
center 11 Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
center_horizontal 1 Place object in the horizontal center of its container, not changing its size.
center_vertical 10 Place object in the vertical center of its container, not changing its size.
clip_horizontal 8 Additional option that can be set to have the left and/or right edges of the child clipped to its container's bounds. The clip will be based on the horizontal gravity: a left gravity will clip the right edge, a right gravity will clip the left edge, and neither will clip both edges.
clip_vertical 80 Additional option that can be set to have the top and/or bottom edges of the child clipped to its container's bounds. The clip will be based on the vertical gravity: a top gravity will clip the bottom edge, a bottom gravity will clip the top edge, and neither will clip both edges.
end 800005 Push object to the end of its container, not changing its size.
fill 77 Grow the horizontal and vertical size of the object if needed so it completely fills its container.
fill_horizontal 7 Grow the horizontal size of the object if needed so it completely fills its container.
fill_vertical 70 Grow the vertical size of the object if needed so it completely fills its container.
left 3 Push object to the left of its container, not changing its size.
right 5 Push object to the right of its container, not changing its size.
start 800003 Push object to the beginning of its container, not changing its size.
top 30 Push object to the top of its container, not changing its size.

更多相关文章

  1. android防止屏幕关闭后后台服务停止运行
  2. Android开发之屏幕属性
  3. Android获取屏幕的宽和高
  4. android获得手机屏幕大小
  5. Android获取屏幕分辨率和dpi
  6. Android屏幕休眠禁止或清除
  7. android典型代码系列(二十二)------按键使上面的EditText抖动

随机推荐

  1. [android UI]应用程序自适应屏幕大小
  2. OPhone/Android的学习(3)—再熟悉几个常
  3. Android 开发技巧总结
  4. Android webview设置背景透明,去掉白色
  5. Android音频系统之AudioPolicyService的
  6. Android中桌面图标显示通知消息的数量
  7. android 网络交互
  8. Android Adapter使用总结
  9. Android(安卓)Intent的用法总结
  10. [Android]关于android sqlite database存