Improper UI - android

Viewed 128

I'm trying to construct an UI as shown in below image:
Please check this as well: https://imgur.com/a/fXPRBez
proper UI
My code:

<androidx.constraintlayout.widget.ConstraintLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="16dp"
                    android:layout_marginTop="24dp"
                    android:layout_marginEnd="16dp"
                    android:background="@drawable/drawableborder"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintTop_toTopOf="parent">

                    <ImageView
                        android:id="@+id/iv_attachment"
                        android:layout_width="18dp"
                        android:layout_height="18dp"
                        android:layout_marginTop="8dp"
                        android:layout_marginEnd="8dp"
                        android:layout_marginRight="8dp"
                        android:layout_marginBottom="8dp"
                        android:paddingStart="@dimen/padding_big"
                        android:paddingEnd="@dimen/padding_big"
                        android:scaleType="centerInside"
                        app:layout_constraintBottom_toBottomOf="parent"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/frameLayout"
                        app:srcCompat="@drawable/ic_gallery" />

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/gv_attach_image"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_marginStart="8dp"
                        android:layout_marginTop="16dp"
                        android:layout_marginEnd="8dp"
                        android:layout_toStartOf="@+id/iv_attachment"
                        android:layout_toLeftOf="@+id/iv_attachment"
                        android:nestedScrollingEnabled="true"
                        android:numColumns="3"
                        android:visibility="gone"
                        app:layout_constraintEnd_toEndOf="parent"
                        app:layout_constraintStart_toStartOf="parent"
                        app:layout_constraintTop_toBottomOf="@+id/tell_us_more" />

                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/tell_us_more"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:hint="@string/what_do_you_need_help"
                        app:layout_constraintTop_toTopOf="parent">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/tell_us_moreone"
                            style="@style/whathelpdoyouneedontextinput"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content" />

                    </com.google.android.material.textfield.TextInputLayout>

                    <FrameLayout
                        android:id="@+id/frameLayout"
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:background="@color/dell_grey2"
                        app:layout_constraintTop_toBottomOf="@+id/gv_attach_image">

                    </FrameLayout>
                </androidx.constraintlayout.widget.ConstraintLayout>  

This produces the UI as given below:
improper UI
As you can see, this creates a small gap between TextInputLayout and the border. How do I fix this?

3 Answers

You can do something like:

<LinearLayout
    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="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="24dp"
    android:layout_marginEnd="16dp"
    android:orientation="vertical"
    >

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tell_us_more"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="@string/hint_tell_us"
        app:boxStrokeColor="@color/......"
        app:placeholderText="Required"
        app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.top">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/tell_us_moreone"   
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </com.google.android.material.textfield.TextInputLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/shape_rounded"
        android:gravity="end">

    <ImageView
        android:id="@+id/iv_attachment"
        android:layout_width="18dp"
        android:layout_height="18dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginBottom="8dp"
        android:paddingStart="16dp"
        android:paddingEnd="16dp"
        android:scaleType="centerInside"
        app:srcCompat="@drawable/ic_menu_gallery" />

    </LinearLayout>


</LinearLayout>

You can apply a shapeAppearanceOverlay to your TextInputLayout to obtain different corners:

<style name="ShapeAppearanceOverlay.top" parent="">
    <item name="cornerSizeBottomRight">0dp</item>
    <item name="cornerSizeBottomLeft">0dp</item>
</style>

In the layout that contains the image use a shape background with only 3 sides:

<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetTop="-2dp">
    <shape>
        <stroke android:width="1dp" android:color="@color/...." />
        <corners 
            android:bottomRightRadius="8dp"
            android:bottomLeftRadius="8dp"/>

        <solid android:color="#FFFFFF"/>
     </shape>
</inset>

Finally the TextInputLayout uses a placeholder with app:placeholderText="Required" and a floating label(hint) with the red asterisk.
Starting from the 1.2.0-alpha05 you can format the hint text.

For example you can just use something like:

<com.google.android.material.textfield.TextInputLayout
    android:hint="@string/hint_tell_us"
    ...>

with:

<string name="hint_tell_us"><font fgcolor='#FF0000'>*</font> Tell us more about the issue</string>

enter image description here

enter image description here

Your layout is not looking good but to salvage what you already have, may be please try to:

  1. Remove style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" under android:id="@+id/tell_us_more"
  2. Add app:boxBackgroundMode="none" under same location (android:id="@+id/tell_us_more")

try this :

xml :

   <androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="16dp"
    android:layout_marginTop="24dp"
    android:layout_marginEnd="16dp"
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
    android:background="@drawable/border_grey">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/txt_more"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:hint="Tell Us More About The Issue"
        android:layout_marginTop="8dp"
        bind:boxBackgroundColor="#FFFFFF"
        bind:layout_constraintEnd_toEndOf="parent"
        bind:layout_constraintStart_toStartOf="parent"
        bind:layout_constraintTop_toTopOf="parent"
        bind:boxBackgroundMode="none">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/tell_us_moreone"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </com.google.android.material.textfield.TextInputLayout>

    <View
        android:id="@+id/line"
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_marginTop="16dp"
        android:background="@color/grey"
        bind:layout_constraintEnd_toEndOf="parent"
        bind:layout_constraintStart_toStartOf="parent"
        bind:layout_constraintTop_toBottomOf="@+id/txt_more" />


    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/iv_attachment"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:scaleType="centerInside"
        bind:layout_constraintBottom_toBottomOf="parent"
        bind:layout_constraintEnd_toEndOf="parent"
        bind:layout_constraintTop_toBottomOf="@+id/line"
        bind:srcCompat="@drawable/ic_menu_gallery" />


</androidx.constraintlayout.widget.ConstraintLayout>

drawable shape :

<shape xmlns:android="http://schemas.android.com/apk/res/android"
   >


<stroke android:color="@color/grey" android:width="1dp"/>
<solid android:color="@color/colorWhite"/>
<corners android:radius="@dimen/radius_8dp"/>


</shape>

note : you can add your RecyclerView Or ... to ui.

Related