android:layout_gravity为什么不能让按钮居中显示?

iceli iceli 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow >
<TextView android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/TextView01"
android:text="Test Toast"/>
</TableRow>
<TableRow >
<Button android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Button01"
android:text="LONG"/>
</TableRow>
<TableRow >
<Button android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Button02"
android:text="SHORT"/>
</TableRow>
</TableLayout>
</RelativeLayout>

为什么 <TableRow >
<Button android:layout_gravity="center_horizontal"
不能使按钮居中显示?
而<TableRow android:gravity="center">
可以使按钮居中显示?
android:gravity:
这个是针对控件里的元素来说的,用来控制元素在该控件里的显示位置。这个显示是对的。
android:layout_gravity:
这个是针对控件本身而言,用来控制该控件在包含该控件的父控件中的位置。这个怎么不能控制Button在TableRow中的位置?
...全文

相关推荐

评论 18
收藏 已收藏
分享
返回顶部
iceli
Android 80,490 成员 91,375 内容