1

Started learning Android 2 days ago. Below is the screenshot of my first application.

enter image description here

The problem is when I change the screen size the text and button below gets cropped out like in the image below.

enter image description here

How do I make the text adjust to the bottom always. Will that be the idle way to handle the text or should I instead make the view scrollable. Sorry if the answer to this is obvious, I am just a newbie.

Below is the code I have.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:srcCompat="@drawable/bg" />

    <TextView
        android:id="@+id/restaurantTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="114dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="497dp"
        android:text="Restaurant"
        android:textColor="@android:color/background_light"
        android:textSize="50sp"
        app:layout_constraintBottom_toTopOf="@+id/textView2"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="8dp"
        android:text="cheeza pizza"
        android:textColor="@android:color/background_light"
        android:textSize="30sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/restaurantTextView" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="8dp"
        android:width="170dp"
        android:background="@drawable/btn_shape_capsule"
        android:drawableRight="@drawable/arrow_right"
        android:padding="15dp"
        android:text="START ORDER"
        android:textColor="@android:color/background_light"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView2" />

</android.support.constraint.ConstraintLayout>
Jitendra A
  • 1,568
  • 10
  • 18
George
  • 3,757
  • 9
  • 51
  • 86

1 Answers1

1
<?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"
    android:background="@color/colorPrimary">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:srcCompat="@drawable/bg"
        tools:ignore="VectorDrawableCompat" />

    <TextView
        android:id="@+id/restaurantTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Restaurant"
        android:textColor="@android:color/background_light"
        android:textSize="50sp"
        android:layout_marginLeft="20dp"
        android:layout_above="@+id/textView2"
         />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/button"
        android:text="cheeza pizza"
        android:layout_marginLeft="20dp"
        android:textColor="@android:color/background_light"
        android:textSize="30sp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/restaurantTextView" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="15dp"
        android:layout_marginLeft="20dp"
        android:background="@drawable/btn_shape_capsule"
        android:drawableRight="@drawable/arrow_right"
        android:text="START ORDER"
        android:textColor="@android:color/background_light"
        android:layout_marginBottom="30dp"
        android:layout_alignParentBottom="true"/>


</RelativeLayout>
Dhara Jani
  • 461
  • 3
  • 10
  • This works fine, but I don't know why... – George Sep 04 '18 at 12:19
  • 1
    This example removes the margins from the `TextView`. They push your text off the screen, in particular the `android:layout_marginTop="497dp"`. He also changed it to a `RelativeLayout` instead of a `ConstraintLayout`, though that's actually a move backwards. `ConstraintLayout` is probably the "better" approach overall and is certainly valid. tl;dr - They took out the top margin from your `TextView`. – MFazio23 Sep 04 '18 at 13:07