gpt4 book ai didi

Android:布局列表标题

转载 作者:太空狗 更新时间:2023-10-29 16:08:38 25 4
gpt4 key购买 nike

我有一个包含两个图像按钮的列表标题。我希望其中一个图像按钮位于左侧,另一个位于右侧。这就是我的 xml 文件现在的样子,但它不起作用,它只是将左侧的两个图像按钮放在一起。我也尝试过不使用额外的 LinearLayouts,但没有成功。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="fill_horizontal"
android:background="@drawable/list_header_background">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="left"
android:background="@drawable/list_header_background">
<ImageButton
android:id="@+id/refreshBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:src="@drawable/ic_refresh"
android:background="@drawable/list_header_background"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="right"
android:background="@drawable/list_header_background">
<ImageButton
android:id="@+id/battleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:src="@drawable/ic_battle"
android:background="@drawable/list_header_background"
/>
</LinearLayout>
</LinearLayout>

最佳答案

正如 kabuko 所写,RelativeLayout 宽度等于父级宽度。当我们在 RelativeLayout 中有一个 subview 时,我们可以使用 android:layout_alignParentXXXXXX="true" 参数使其( subview )与父 View 相应地对齐。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="@drawable/list_header_background">
<ImageButton
android:id="@+id/refreshBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:src="@drawable/ic_refresh"
android:layout_alignParentLeft="true"
android:background="@drawable/list_header_background"
/>
<ImageButton
android:id="@+id/battleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:src="@drawable/ic_battle"
android:layout_alignParentRight="true"
android:background="@drawable/list_header_background"
/>
</RelativeLayout>

关于Android:布局列表标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8301451/

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