Wrong app display on both physical and virtual device

171 views Asked by At

I tried on both emulator and physical device ,with different layouts, but app shows only about sixty percent of layout,like its exceeding the visible screen and some component goes under.

I tried to use a scroll view,but no success.

<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:background="#242323"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="395dp"
        android:layout_height="715dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">
        <EditText
            android:id="@+id/edittext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="blah blah"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            />

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="press"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/edittext"
            />
    </RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
3

There are 3 answers

4
Kabir On

In your code,try to change this:
from

 <RelativeLayout
        android:layout_width="395dp"
        android:layout_height="715dp"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

to

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">
1
Furqan Khan On

When using constraint layout you need to link your views to some other view/boundry. In your case your RelativeLayout was not linked to parent, and you were using an extra Layout so remove the Constraint layout and use just Relative layout. That will work.

Try the following xml

<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"
    android:background="#242323"
    tools:context=".MainActivity">
        <EditText
            android:id="@+id/edittext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:hint="blah blah"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            />

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="press"
            android:layout_centerHorizontal="true"
            android:layout_below="@id/edittext"
            />
    </RelativeLayout>
0
Timi1ehin On

Remove the relative layout and just use constraint layout only. Note that your button and edittext have to be constrained to the parent view. Learn more about Constraint Layout at https://developer.android.com/reference/android/support/constraint/ConstraintLayout

Try the following xml

<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:background="#242323"
    tools:context=".MainActivity">


    <EditText
        android:id="@+id/edittext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:hint="blah blah"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/edittext"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        android:text="press"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/edittext" />
</androidx.constraintlayout.widget.ConstraintLayout>