LinearLayout里面TableLayout整体居中

有两种方法

方法一:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/mai"
  android:gravity="center"       //关键的一句
      >
<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stretchColumns="1" 
    android:orientation="vertical"
    android:gravity="center"
   >


    <TableRow>。。。。。。。



方法二:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" 
    android:background="@drawable/mai"
  
      >
<TableLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:stretchColumns="1" 
    android:orientation="vertical"
    android:gravity="center"
    android:layout_weight="1">


    <TableRow>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答:以下是各个布局的常用属性及作用: LinearLayout: - orientation:设置组件排列方向,可以是水平或垂直。 - gravity:设置组件在布局中的对齐方式,可以是左对齐、右对齐、居中或者填充满。 - layout_weight:设置组件在布局中所占比例,用于让多个组件占据不同的空间。 TableLayout: - stretchColumns:指定要拉伸的列,可以是一个或多个。 - shrinkColumns:指定要压缩的列,可以是一个或多个。 - collapseColumns:指定要隐藏的列,可以是一个或多个。 - layout_column:指定组件要显示在哪一列。 RelativeLayout: - layout_alignParentTop/bottom/left/right:设置组件相对于父容器的对齐方式。 - layout_above/below/toLeftOf/toRightOf:设置组件相对于其他组件的对齐方式。 - layout_centerInParent:将组件居中于父容器。 - layout_centerHorizontal/Vertical:将组件居中于父容器的水平/垂直方向。 FrameLayout: - layout_gravity:设置组件在布局中的对齐方式,可以是左上角、右上角、居中或者填充满。 - foreground:设置前景,可以是一张图片或一个颜色。 GridLayout: - rowCount/columnCount:指定行数和列数。 - layout_row/layout_column:指定组件所在的行和列。 - layout_gravity:设置组件在格子里的对齐方式。 ConstraintLayout: - layout_constraintTop_toTopOf/bottom_toBottomOf/left_toLeftOf/right_toRightOf:将组件对齐到其他组件或父容器的上下左右边界。 - layout_constraintStart_toStartOf/end_toEndOf:将组件对齐到其他组件或父容器的开始/结束位置。 - layout_constraintWidth_percent/height_percent:设置组件宽度/高度为父容器宽度/高度的百分比。 - layout_constraintGuide_percent:添加一个辅助线,可以在设计时帮助组件对齐。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值