gpt4 book ai didi

Android:居中对齐 ImageButtons

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:34:20 27 4
gpt4 key购买 nike

我有 2 个像这样的 ImageButon

enter image description here

我已尽一切努力使它在屏幕中央正确对齐。作为 android 的新手,我不知道该怎么做。我怎样才能实现将这两个图像按钮对齐在屏幕中央的目标

这是我的布局xml

<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:stretchColumns="1">
<TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent"
android:layout_height="wrap_content">

<ImageButton android:id="@+id/btn_Show"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Show" android:src="@drawable/cmd_result_show"
android:layout_gravity="right" android:background="@android:color/transparent" />

<ImageButton android:id="@+id/btn_showAll"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Detailed Show" android:layout_gravity="center"
android:src="@drawable/cmd_result_details" android:background="@android:color/transparent" />
</TableRow>
</TableLayout>

最佳答案

我希望你直接有这些按钮的图片。所以这个设置text属性是没有用的。使用 RelativeLayout 可以轻松开发此类屏幕。

下面我附上了代码。如果有任何问题,请查看并添加评论。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="center_horizontal">

<ImageButton android:id="@+id/btn_Show"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/cmd_result_show" />

<ImageButton android:id="@+id/btn_showAll"
android:layout_toRightOf="@id/btn_Show" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:background="@drawable/cmd_result_details" />
</RelativeLayout>

关于Android:居中对齐 ImageButtons,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5321252/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com