Home > front end >  Objects disappearing and distorting depending on the screen resolution
Objects disappearing and distorting depending on the screen resolution

Time:01-15

im making a android app and I noticed a problem about the resolution and the object...

Basically the smaller the resolution gets the objects disappear like in this video

If you need it here's the code

<?xml version="1.0" encoding="utf-8"?>
<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=".dateselector_activity">

    <ImageButton
        android:id="@ id/btn_add"

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"

        android:layout_marginStart="320dp"
        android:layout_marginTop="775dp"

        android:layout_marginEnd="40dp"
        android:layout_marginBottom="40dp"

        android:background="@drawable/circle_button"
        android:elevation="20dp"
        android:src="@drawable/ic_plusbuttonvector"
        android:textColor="@color/white"
        android:textSize="20sp"

        app:layout_constraintVertical_bias="1.0"
        tools:ignore="HardcodedText,SpeakableTextPresentCheck"
        tools:visibility="visible" />

    <TextView
        android:id="@ id/clockTimeText"
        android:layout_width="wrap_content"
        android:layout_height="34dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="160dp"
        android:layout_marginTop="295dp"
        android:layout_marginEnd="177dp"
        android:layout_marginBottom="537dp"
        android:text="Hello hjh"
        app:layout_constraintBottom_toTopOf="@ id/btn_add"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        tools:ignore="HardcodedText"
        tools:text="@tools:sample/date/ddmmyy" />

</RelativeLayout>

Is there any way to make objects reposition based on the screen resolution and keep them the same width and height Thanks

CodePudding user response:

Solved it! For other people that have this problem you need to use:

androidx.constraintlayout.widget.ConstraintLayout

Instead of:

RelativeLayout
  • Related