Search code examples
androidandroid-layoutvisual-glitch

Extra spacing problem in 4K resolution android device


I am developing chat application android. It works pretty well in all the devices.

But 4K resolution devices like Samsung s8+ and one plus 6t, It leaves right side extra spacing automatically. I have not given any, margin and padding.

refer [this screenshot].

my view file is something like this:

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end"
        android:layout_marginStart="64dp"
        android:layout_marginLeft="64dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="12dp"
        android:layout_marginRight="12dp"
        android:background="@drawable/sender_bg"
        android:gravity="center_vertical"
        android:orientation="vertical"
        android:padding="16dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fontFamily="@font/karla_regular"
            android:text="Yes, and it will be safe. My promise"
            android:textColor="@color/colorPrimary"
            android:textSize="16sp" />

    </LinearLayout>
</layout>

can any one help me with the solution. Thanks in advance


Solution

  • Make the linear layout width match parent

     <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:layout_marginStart="64dp"
            android:layout_marginLeft="64dp"
            android:layout_marginTop="8dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="12dp"
            android:layout_marginRight="12dp"
            android:background="@drawable/sender_bg"
            android:gravity="center_vertical"
            android:orientation="vertical"
            android:padding="16dp">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:fontFamily="@font/karla_regular"
                android:text="Yes, and it will be safe. My promise"
                android:textColor="@color/colorPrimary"
                android:textSize="16sp" />
    
        </LinearLayout>
    </layout>