2

I referred most of the questions in Stackoverflow related to this topic and successfully placed my Linear Layout in a ScrollView. But I can't scroll it. The outline of my Activity is-

enter image description here

Here is the XML code of ScrollView-

<ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" >

                <LinearLayout
                    android:id="@+id/linearLayoutUP1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:layout_weight="1"
                    android:orientation="vertical" >

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

                        <TextView
                            android:id="@+id/textViewUP1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@color/Chocolate"
                            android:gravity="center"
                            android:padding="10dp"
                            android:text=" "
                            android:textAppearance="?android:attr/textAppearanceLarge"
                            android:textColor="@color/Black"
                            android:textStyle="bold" />
                    </LinearLayout>

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

                        <TextView
                            android:id="@+id/textViewUP2"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="@color/Chocolate"
                            android:gravity="center"
                            android:padding="10dp"
                            android:text="User ID : "
                            android:textColor="@color/White"
                            android:textSize="16sp"
                            android:textStyle="bold" />
                    </LinearLayout>

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

                        <TextView
                            android:id="@+id/textViewUP4"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="@color/Chocolate"
                            android:gravity="center"
                            android:padding="10dp"
                            android:text="Gender : "
                            android:textColor="@color/White"
                            android:textSize="16sp"
                            android:textStyle="bold" />
                    </LinearLayout>

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

                        <TextView
                            android:id="@+id/textViewUP3"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:background="@color/Chocolate"
                            android:gravity="center"
                            android:padding="10dp"
                            android:text="Your Groups"
                            android:textColor="@color/White"
                            android:textSize="16sp"
                            android:textStyle="bold" />

                        <GridView
                            android:id="@+id/gridViewUP1"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:numColumns="1"
                            android:padding="5dp" >
                        </GridView>
                    </LinearLayout>
                </LinearLayout>
                </ScrollView>

As you can see there is a GridView in the last LinearLayout. This GridView was scrollable before adding ScrollView. After adding ScrollView the layout named 'linearLayoutUP1' cannot be scrolled. How can I make it scrollable vertically ?

Tomin Jacob
  • 333
  • 1
  • 9
  • 24
  • Can you post your code. In order to seedependencies. – Supriya Sep 24 '14 at 17:48
  • post your xml file too.. – Lal Sep 24 '14 at 17:49
  • try adding `android:fillViewport="true"` to your `ScrollView` – Lal Sep 24 '14 at 17:56
  • @Lal Now scroll bar is appearing, but still I can't scroll. – Tomin Jacob Sep 24 '14 at 18:00
  • try hardcoding the height for the first LinearLayout..ie change wrap_content to some 1000dp or so..just for testing.. – Lal Sep 24 '14 at 18:04
  • and also what theme are you using???is it any fullscreen theme??? – Lal Sep 24 '14 at 18:05
  • also check if there is `android:windowSoftInputMode="adjustPan"` for your activity tag in manifr=est..if yes try after removing that... – Lal Sep 24 '14 at 18:05
  • @Lal Am using full screen theme. android:windowSoftInputMode="adjustPan" is no where in manifest file. – Tomin Jacob Sep 24 '14 at 18:07
  • ok...so i think you are using `android:theme="@android:style/Theme.NoTitleBar.Fullscreen"` ..try changing that to `android:theme="@android:style/Theme.NoTitleBar"` ..ie without fullscreen...try it.. – Lal Sep 24 '14 at 18:10
  • @Lal Am not having a single Activity in my app. Every Activity is full screen. So when I made the change as you said now, I got error. – Tomin Jacob Sep 24 '14 at 18:14
  • you are changing the theme right??? – Lal Sep 24 '14 at 18:17
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/61853/discussion-between-manu-jacob-and-lal). – Tomin Jacob Sep 24 '14 at 18:19

3 Answers3

2

I think nesting scrollable views in Android is considered bad design, and may not work properly. GridViews are inherently scrollable.

If you want to keep it, try looking here: Problems with GridView inside ScrollView in android

Community
  • 1
  • 1
JstnPwll
  • 8,585
  • 2
  • 33
  • 56
1

Try hardcoding the height for the first LinearLayout..ie change wrap_content to some 1000dp or so. This will make it scrollable. I'm not at all sure whether this is the right way to solve the problem..But was telling you what I did when I faced the same situation.

Also, if you are using android:theme="@android:style/Theme.NoTitleBar.Fullscreen" ..try changing that to android:theme="@android:style/Theme.NoTitleBar" ..ie without fullscreen...

Again, check if there is android:windowSoftInputMode="adjustPan" for your activity tag in manifest..if yes try after removing that.

These are the solutions which i tried and worked when i faced a similar situatuion.

android activity always start scrolled to the bottom-to solve this problem please add android:focusableInTouchMode="true" to your LinearLayout..

Lal
  • 14,726
  • 4
  • 45
  • 70
0

It is not recommended to you any kind of scrollable view inside a ScrollView.

You may want to check this out in your case and see if it works.

http://lubosplavucha.com/java/2014/05/05/gridview-scrollview-issue/

sundar.siva
  • 61
  • 1
  • 2
  • How should I edit my code to make it working ? I extends Activity to my class and in the example you provided GridView is extended to that class. – Tomin Jacob Sep 24 '14 at 18:02