Android: EditText next to ImageView - EditText as wide as possible

I would like to have EditTextand ImageViewnext to each other; ImageViewhas a fixed width, EditTextshould take everything else.

I'm trying to do it through

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="horizontal" android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical" android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <EditText android:id="@+id/edit_select_stop" android:layout_width="fill_parent" android:layout_height="wrap_content" />
            </LinearLayout>
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical" android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ImageView android:layout_gravity="center_vertical"
                    android:layout_width="39dp" android:minWidth="39dp"
                    android:layout_height="wrap_content" android:src="@drawable/icon_time"
                    android:id="@+id/image_select_time"></ImageView>
            </LinearLayout>
        </LinearLayout>

But now EditText takes up the entire width and closes the image.

How can I achieve that an EditText "ends" before an ImageView?

+2
source share
3 answers
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditText
android:id="@+id/edit_select_stop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
</EditText>
<ImageView
android:id="@+id/image_select_time"
android:layout_width="39dp"
android:layout_height="wrap_content"
android:layout_weight="1"
>
</ImageView>
</LinearLayout>
+3
source

You can also use RelativeLayoutto execute it. Just assign properties

 android:layout_toLeftOf="@+id/id_of_your_imageview" 
 android:layout_width="fill_parent"

in EditTextand

android:layout_alignParentRight="true"

to yours ImageView, keeping a fixed width value.

+5
source

, .

() , , android:gravity="center_vertical"

.

0

Source: https://habr.com/ru/post/1792521/


All Articles