GAIUS12100
GAIUS12100

Reputation: 45

Kotlin Layout Doesn't Fit the Screen

PROBLEM IMAGE CLICK HERE

My layout doesn't fit the screen How do I solve this? Thank you for your help. I was trying to show my data from ViewModel.

This is my XML code here

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/detailTopText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView" />
        <ImageView
            android:id="@+id/detailImage"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitCenter"
            android:src="@drawable/ic_launcher_background" />
        <TextView
            android:id="@+id/detailDesText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView2" />
    </LinearLayout>
</ScrollView>

Upvotes: 0

Views: 460

Answers (3)

Haris
Haris

Reputation: 395

Here is your new layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/detailTopText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView" />

            <ImageView
                android:id="@+id/detailImage"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitCenter"
                app:srcCompat="@drawable/flatwoods_img_btn_" />

            <TextView
                android:id="@+id/detailDesText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="TextView2" />


        </LinearLayout>
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 1

kharismarizqii
kharismarizqii

Reputation: 58

You can add paddingTop or marginTop properties with action bar size to the ScrollView

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="?android:attr/actionBarSize">

Upvotes: 0

franvillacis
franvillacis

Reputation: 319

Try setting margin top in your linear layout

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:orientation="vertical">

Upvotes: 0

Related Questions