Home > Net >  ScrollView is not appearing in android app
ScrollView is not appearing in android app

Time:11-27

I've gone through all the other answers and most of them didn't use wrap_content for the child LinearLayout but my case is different:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:gravity="center"
              tools:context=".MainActivity">
    <ScrollView
            android:id="@ id/Scroll"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <LinearLayout
                android:id="@ id/LL2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">


    <TextView
            android:id="@ id/TV1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:text="Test"
            android:clickable="false" android:textSize="20sp"/>
    <TextView
            android:id="@ id/link"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:text="Loading..."
    />

    <TextView
            android:id="@ id/TV2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:text="Test"
            android:textSize="20sp"/>

    <TextView
            android:id="@ id/TV3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:text="Test"
            android:textSize="20sp"/>

    <TextView
            android:id="@ id/TV4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:text="Earnings:"
            android:textSize="20sp"/>

    <TextView
            android:id="@ id/User_earnings"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:text="Loading..."
            android:textSize="20sp"/>

    <TextView
            android:id="@ id/TV6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="15dp"
            android:text="Test"
            android:textSize="20sp"/>



    <Button
            android:id="@ id/btnLogOut"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_margin="15dp"
            android:text="Logout"/>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

EDIT:

The code is not fitting on screen in landscape mode, hence I'm using scroll view for that. Based on the thoughtful comments and answers mentioned below, I've made the following changes to the code:

  • Set android:layout_height="match_parent" in ScrollView.
  • Set android:layout_height="wrap_content" in the very first LinearLayout.
  • Added ids for ScrollView and LinearLayout.

Unfortunately , the problem still persists.

CodePudding user response:

I suggest you are not setting android:id="@ id/ViewID" for both the Linearlayout and ScrollView in your xml code.

CodePudding user response:

Please check your layout by adding a few more textviews. The given xml code may fit on the screen and therefore does not scroll.

  • Related