0

I want to add scrollview to whole of my activity.I have given weight to each and every layout and view as I want my screen to be generic.But by adding scrollview on the top of my activity its disorganinze my whole screen, I couldnt able to see all of my text and adds extra spaces between every thing.I hope that I have clearly stated my problem,its really irritating me as I have given weight to every layout and view than why its changing the view of my screen. Also I have seen the solutions of same question already posted over here but I didn't satisfy with that. All I want is the simple way to scroll my whole activity without disturbing the layout and text. Here are the images of my activity after adding scrollview :

[enter image description here

Here is my XML code :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="3"
    android:background="@drawable/empty"
    tools:context=".story_activity">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Story Name"
        android:textAlignment="center"
        android:textColor="#fff"
        android:layout_marginTop="5dp"
        android:textSize="20sp"
        android:textStyle="bold"></TextView>
       <!-- android:layout_marginLeft="140dp"-->/>

    <LinearLayout
        android:layout_marginTop="5dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:weightSum="3"
        android:background="@drawable/story_des"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="15dp"
        android:alpha="0.8"
        android:orientation="vertical">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:orientation="vertical">

    <ImageView
        android:layout_marginTop="10dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/lion"/>

</LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1.3"
            android:weightSum="1.2"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="vertical">

            <ScrollView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scrollbars="none">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters.This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters.This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters."


                android:padding="15dp"

                android:textColor="#fff"
                android:textSize="15sp"
                android:id="@+id/story_content"/>
                <!--android:scrollbars = "vertical"-->
            </ScrollView>
            </LinearLayout>

            <LinearLayout

                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="0.3"
                android:orientation="horizontal">
                <TextView

                    android:id="@+id/story_rate"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Rate This Story"
                    android:layout_gravity="center"
                    android:padding="5dp"
                    android:layout_marginLeft="10dp"
                    android:textSize="15sp"

                    android:textColor="#1e5aaa"
                    android:textStyle="bold"/>

                <ImageView
                    android:id="@+id/rate"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_toRightOf="@+id/story_rate"
                    android:src="@drawable/star"
                    android:layout_gravity="center"
                    />
                <ImageView
                    android:id="@+id/rate1"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_toRightOf="@+id/rate"
                    android:layout_gravity="center"
                    android:src="@drawable/star"
                    />
                <ImageView
                    android:id="@+id/rate2"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_toRightOf="@+id/rate1"
                    android:src="@drawable/star"
                    android:layout_gravity="center"
                    />
                <ImageView
                    android:id="@+id/rate3"
                    android:layout_width="20dp"
                    android:layout_height="20dp"
                    android:layout_toRightOf="@+id/rate2"
                    android:src="@drawable/star"
                    android:layout_gravity="center"
                    />
            </LinearLayout>

</LinearLayout>



<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.7"
    android:orientation="vertical">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:src="@drawable/line"/>
    <RelativeLayout
        android:layout_marginBottom="-90dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/author_image"
        android:layout_width="80dp"
        android:layout_height="60dp"

        android:layout_marginLeft="20dp"
        android:layout_marginBottom="20dp"
        android:src="@drawable/as" />


    <TextView
        android:id="@+id/author_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:layout_marginLeft="2dp"
        android:textSize="15dp"
        android:textColor="#fff"
        android:layout_toRightOf="@+id/author_image"
        android:fontFamily="century-gothic"

        android:text="Author Title"
        />
    <TextView
        android:id="@+id/pub_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:layout_marginTop="3dp"
        android:layout_toRightOf="@+id/author_image"
        android:layout_below="@+id/author_title"
        android:layout_marginLeft="2dp"
        android:textSize="15dp"
        android:textColor="#fff"
        android:fontFamily="century-gothic"
        android:text="Pve sentences, cjajsxa "
        />
    </RelativeLayout>

</LinearLayout>

</LinearLayout>
    </LinearLayout>
</ScrollView>
Umair Iqbal
  • 1,959
  • 1
  • 19
  • 38
  • 1
    Possible duplicate of [How to make whole activity scrollable according to the data inside it](https://stackoverflow.com/questions/33582546/how-to-make-whole-activity-scrollable-according-to-the-data-inside-it) – B001ᛦ Jul 17 '18 at 10:03
  • I have seen that but I didn't get my solution from that question. – Umair Iqbal Jul 17 '18 at 10:05

1 Answers1

1

remove weightSum and weight from layout

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/empty"
        android:orientation="vertical"
        tools:context=".story_activity">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="Story Name"
            android:textAlignment="center"
            android:textColor="#fff"
            android:textSize="20sp"
            android:textStyle="bold"></TextView>
        <!-- android:layout_marginLeft="140dp"-->/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15dp"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="5dp"
            android:alpha="0.8"
            android:background="@drawable/story_des"
            android:orientation="vertical">

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

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="100dp"
                    android:layout_marginTop="10dp"
                    android:src="@drawable/lion" />
            </LinearLayout>

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

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

                    <TextView
                        android:id="@+id/story_content"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:padding="15dp"
                        android:text="This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters.This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters.This specification does not indicate the behavior, rendering or otherwise, of space characters other than those explicitly identified here as white space characters. For this reason, authors should use appropriate elements and styles to achieve visual formatting effects that involve white space, rather than space characters."
                        android:textColor="#fff"
                        android:textSize="15sp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.3"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/story_rate"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="10dp"
                        android:padding="5dp"
                        android:text="Rate This Story"
                        android:textColor="#1e5aaa"
                        android:textSize="15sp"
                        android:textStyle="bold" />

                    <ImageView
                        android:id="@+id/rate"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center"
                        android:layout_toRightOf="@+id/story_rate"
                        android:src="@drawable/star" />

                    <ImageView
                        android:id="@+id/rate1"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center"
                        android:layout_toRightOf="@+id/rate"
                        android:src="@drawable/star" />

                    <ImageView
                        android:id="@+id/rate2"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center"
                        android:layout_toRightOf="@+id/rate1"
                        android:src="@drawable/star" />

                    <ImageView
                        android:id="@+id/rate3"
                        android:layout_width="20dp"
                        android:layout_height="20dp"
                        android:layout_gravity="center"
                        android:layout_toRightOf="@+id/rate2"
                        android:src="@drawable/star" />
                </LinearLayout>
            </LinearLayout>

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

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="30dp"
                    android:src="@drawable/line" />

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:id="@+id/author_image"
                        android:layout_width="80dp"
                        android:layout_height="60dp"
                        android:layout_marginBottom="20dp"
                        android:layout_marginLeft="20dp"
                        android:src="@drawable/as" />

                    <TextView
                        android:id="@+id/author_title"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="2dp"
                        android:layout_toRightOf="@+id/author_image"
                        android:fontFamily="century-gothic"
                        android:text="Author Title"
                        android:textColor="#fff"
                        android:textSize="15dp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/pub_content"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/author_title"
                        android:layout_marginLeft="2dp"
                        android:layout_marginTop="3dp"
                        android:layout_toRightOf="@+id/author_image"
                        android:fontFamily="century-gothic"
                        android:text="Pve sentences, cjajsxa "
                        android:textColor="#fff"
                        android:textSize="15dp"
                        android:textStyle="bold" />
                </RelativeLayout>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</ScrollView>
Vinay Rathod
  • 1,262
  • 1
  • 10
  • 19
  • Thanku but I were using this approach to make generic screen after removing weightsum and layout_weight wont it disorganinze the layout on different screens – Umair Iqbal Jul 17 '18 at 10:33
  • if you have enough content, then you can definitely use weightsum and layout_weight else you can use scrollview – Vinay Rathod Jul 17 '18 at 10:36