实现button在屏幕居中

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

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. 安卓报错:AS Error inflating class android.support.v7.widget.
  2. Android(安卓)设置View 圆角
  3. ProgressBar的简单使用
  4. android防止屏幕关闭后后台服务停止运行
  5. Android使用MQTT协议
  6. Android(安卓)--spinner构造下垃菜单
  7. Android(安卓)ImageView图片自适应
  8. Android多屏幕适配
  9. Android(安卓)Screen Monitor使用

随机推荐

  1. Activity去掉标题栏失败(使用AppCompat)
  2. 点击button然后改变其中文字的颜色
  3. android getResources的作用
  4. 在Android中通过代码切换到指定 WiFi
  5. Android通过http协议POST传输方式
  6. Android 系统菜单与自定义菜单
  7. android 安装 出现Android Native Develo
  8. Linux下Android ADB驱动安装详解
  9. Android从view得到bitmap及bitmap叠加和
  10. Android(安卓)canvas.drawBitmap实现透明