3

Below is my XML code, I want the whole view to scroll, but it's just not working, please help, with what's wrong;

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/app_icon"
    android:layout_marginTop="20dp"
    android:layout_gravity="center_horizontal"/>

<TextView
    android:id="@+id/textView_app_version"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:layout_gravity="center"/>

<TextView
    android:id="@+id/textView_content"
    android:layout_width="match_parent"
    android:layout_marginTop="15dp"
    android:layout_height="386dp"
    android:gravity="center"></TextView>

</LinearLayout>
</ScrollView>

I've tried using, android:fillViewport="true"

but of no help.

6
  • That view fit in screen so it doesn't scroll at all. Commented Jun 26, 2015 at 7:19
  • So, what should I do? Commented Jun 26, 2015 at 7:20
  • Your xml is correct it would automatically scroll when there are more components like edittext or imageviews Commented Jun 26, 2015 at 7:21
  • but, my textview has lengthy content, which doesn't fit into screen, in that case it should scroll, right? Commented Jun 26, 2015 at 7:23
  • 1
    make your scrollview layout_width and layout_height as fill_parent Commented Jun 26, 2015 at 7:27

4 Answers 4

2

A ScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects.

So here you have to take LinearLayout or RelativeLayout and then you have to put different hierarchy of component.

Android : buttons not visible in scrollview

here i have given answer of Some problem so you can follow this for solve your problem with clearing your concept.

Sign up to request clarification or add additional context in comments.

Comments

1

Try like this ,Scrolling will work till End

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

     <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >


            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/app_icon"
                android:layout_marginTop="20dp"
                android:layout_gravity="center_horizontal"/>

            <TextView
                android:id="@+id/textView_app_version"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:layout_gravity="center"/>

            <TextView
                android:id="@+id/textView_content"
                android:layout_width="match_parent"
                android:layout_marginTop="15dp"
                android:layout_height="386dp"
                android:gravity="center"/>

        </LinearLayout>
    </ScrollView>
</Relativelayout>

Comments

1

If ScrollView fits to your device screen it would not be scrollable, so make sure content inside ScrollView takes space larger than your screen size.

Comments

0

systematix Try this,here you getting scroll.

<?xml version="1.0" encoding="utf-8"?>

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/textView_app_version1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="hello" />

    <TextView
        android:id="@+id/textView_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:gravity="center"
        android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/textView_app_version"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="hello" />

    <TextView
        android:id="@+id/textView_content1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:gravity="center"
        android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/textView_app_version2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="hello" />

    <TextView
        android:id="@+id/textView_content3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:gravity="center"
        android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="20dp"
        android:src="@mipmap/ic_launcher" />

    <TextView
        android:id="@+id/textView_app_version4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:text="hello" />

    <TextView
        android:id="@+id/textView_content4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:gravity="center"
        android:text="fahfhahffshfs fsfhshf fshfs sflshf sflsh fhsfhslfh fshflshf hslfh slfhslfhslfhs fhslhf"></TextView>


</LinearLayout>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.