gpt4 book ai didi

android如何使用layout_height ="match_parent"将Imagebutton放在右边

转载 作者:行者123 更新时间:2023-11-30 03:55:08 25 4
gpt4 key购买 nike

我想在 2 个 EditText 的右边有一个 ImageButton

我试过了

RelativeLayout:但是 ImageView layout_height="match_parent" 不起作用

LinearLayout:但无法在不被 EditText 推出的情况下将按钮移至右侧。 LinearLayout 的 LayoutDirection="rtl" 本来可以工作,但它不再存在了

编辑:

我不想在宽度/高度上使用特定值

我有这个,我现在把高度设置为 90dp,但我不想让它放在那里

<RelativeLayout
android:id="@+id/login_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >

<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username"
android:layout_toLeftOf="@id/login"
android:inputType="text"
android:gravity="center_horizontal" />

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password"
android:layout_below="@id/username"
android:layout_toLeftOf="@id/login"
android:inputType="textPassword"
android:gravity="center_horizontal" />

<!-- TODO: FIX android:layout_height="match_parent" -->
<ImageButton
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="90dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="@string/login"
android:scaleType="fitCenter"
android:src="@drawable/login_button" />

</RelativeLayout>

最佳答案

您可以使用以下之一:

<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >

<EditText
android:id="@+id/edtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions" />

<ImageButton
android:id="@+id/imgv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/edtxt"
android:contentDescription="@string/saveBtn"
android:src="@drawable/ic_launcher" />
</RelativeLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:orientation="horizontal"
android:weightSum="2" >

<EditText
android:id="@+id/edt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
/>

<ImageButton
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
</LinearLayout>

编辑:

我更新了你的代码。检查一下。它在我的模拟器中显示了你想要的输出。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/login_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp" >

<ImageButton
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"

android:contentDescription="@string/username"
android:src="@drawable/ic_launcher" />


<EditText
android:id="@+id/uname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/login"
android:gravity="center_horizontal"
android:hint="@string/username"
android:inputType="text" />

<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:layout_below="@id/uname"
android:layout_toLeftOf="@id/login"
android:gravity="center_horizontal"
android:hint="@string/password"
android:inputType="textPassword" />

</RelativeLayout>

输出:

Screenshot of output

关于android如何使用layout_height ="match_parent"将Imagebutton放在右边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13472896/

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