简体   繁体   中英

Why my RelativeLayout does not extend to the left set as I increase the width? xml

I want to increase width of my editTexts and ImageView that are inside of the RelativeLayout, but as I increase the width of the RelativeLayout it starts to extend only to the right excluding the left side, but I want both of them to extend . What is the problem?

The code is provided below for you inspection:

<?xml version="1.0" encoding="utf-8"?>
<data>

    <variable
        name="AuthViewModel"
        type="com.example.auth.ui.auth.AuthViewModel"/>

</data>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.auth.AuthActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="261dp"
            >

            <ImageView
                android:layout_width="154dp"
                android:layout_height="154dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="93dp"
                android:src="" />
        </FrameLayout>

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="62dp"
            android:layout_marginTop="36.7dp"
            android:layout_marginRight="62dp"
            android:background="@drawable/blue_border_rounded_cornwe">
            <!-- INPUT -->
            <EditText
                android:id="@+id/username_input"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/username_icon"
                android:background="@android:color/transparent"
                android:fontFamily="@font/poppins_regular"
                android:hint="Логин"
                android:text="@={AuthViewModel.email}"
                android:inputType="textEmailAddress"
                android:maxLines="1"
                android:paddingLeft="17dp"
                android:paddingTop="15dp"
                android:paddingBottom="15dp"
                android:textCursorDrawable="@drawable/cursor_color"
                android:textSize="12sp" />
            <!-- ICON -->
            <ImageView
                android:id="@+id/username_icon"
                android:layout_width="16.7dp"
                android:layout_height="12.3dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="17dp"
                android:src="@drawable/sr_email" />
        </RelativeLayout>
        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="62dp"
            android:layout_marginTop="12.7dp"
            android:layout_marginRight="62dp"
            android:background="@drawable/blue_border_rounded_cornwe">
            <!-- INPUT -->

            <EditText
                android:id="@+id/pass"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+id/icon"
                android:background="@android:color/transparent"
                android:fontFamily="@font/poppins_regular"
                android:hint="Пароль"
                android:text="@={AuthViewModel.password}"
                android:inputType="textPassword"
                android:maxLength="10"
                android:maxLines="1"
                android:paddingLeft="17dp"
                android:paddingTop="15dp"
                android:paddingBottom="15dp"
                android:textCursorDrawable="@drawable/cursor_color"
                android:textSize="12sp" />
            <!-- ICON -->
            <ImageView
                android:id="@+id/icon"
                android:layout_width="16.7dp"
                android:layout_height="12.3dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="17dp"
                android:src="@drawable/sr_password" />
        </RelativeLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="62dp"
            android:layout_marginTop="20.7dp"
            android:layout_marginRight="62dp"
            android:background="@drawable/blue_fill__rounded_color"
            android:fontFamily="@font/poppins_medium"
            android:gravity="center"
            android:paddingTop="14dp"
            android:paddingBottom="14dp"
            android:text="Войти"
            android:onClick="@{AuthViewModel::onLoginButtonClicked}"
            android:textColor="#ffffff"
            android:textSize="12sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="35dp"
            android:gravity="center"
            android:orientation="horizontal">

        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

Thank you ahead for solving this silly question

 <LinearLayout
    android:layout_width="match_parent"
    android:weightSum="10"
    android:layout_height="wrap_content"
    
    >
    <!-- INPUT -->
    <EditText
        android:id="@+id/username_input"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_weight="9"
        android:layout_toRightOf="@+id/username_icon"
        android:background="@android:color/transparent"
        android:hint="Логин"
        android:text="fdgfdgsgsdgsdgsdgsdgsdgsgdssdgsdgsgd"
        android:inputType="textEmailAddress"
        android:maxLines="1"
        android:paddingLeft="17dp"
        android:paddingTop="15dp"
        android:paddingBottom="15dp"
       
        android:textSize="12sp" />
    <!-- ICON -->
    <ImageView
        android:id="@+id/username_icon"
        android:layout_width="16.7dp"
        android:layout_weight="1"
        android:layout_height="12.3dp"
        android:background="#000"
        android:layout_centerVertical="true"
        android:layout_marginLeft="17dp"
        />
</LinearLayout>

use linear layout instead the weightSum will help in arrangment and gravity will help it stay central will update if i find any way with Relative layout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM