Scroll View not showing all the views in android
Asked Answered
A

7

5

I am unable to see the top most views under ScrollView. I had placed the scrollview under Relative layout. ScrollView has a child layout i.e. Linear layout which has some series of buttons. Problem is that i am unable to see the top most views which are present in the ScrollView.

Below is the layout xml code.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#217d27"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:onClick="backPressed"
            android:text="Back"
            android:textColor="#000" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="Heading Text"
            android:textColor="#fff"
            android:textSize="20sp" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:onClick="homeButtonClicked"
            android:text="Home"
            android:textColor="#000" />
    </RelativeLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fadingEdge="none"
        android:fillViewport="true" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="#fff"
            android:orientation="vertical" >

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Button 1"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 2"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 3"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 4"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 5"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 6"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 7"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 8"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 9"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 10"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 11"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 12"
                android:textColor="@color/black" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>

Please see the screen shot for reference.

Screen shot

Awning answered 26/11, 2013 at 12:2 Comment(4)
Use Relative layout instead of linear as parent.Magnet
Nope Relative layout is also not working. I am getting the same result.Awning
your code is 99% perfect just remove 1 line only see my answer i update your code dude and u welcome always :)Essen
I shouldn't have used this in Linear Layout android:layout_gravity="center".Awning
E
13

just remove this line in linear layout which is direct child of scroll view android:layout_gravity="center" try this code which is updated

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#217d27"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp" >

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:onClick="backPressed"
            android:text="Back"
            android:textColor="#000" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:gravity="center"
            android:text="Heading Text"
            android:textColor="#fff"
            android:textSize="20sp" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:onClick="homeButtonClicked"
            android:text="Home"
            android:textColor="#000" />
    </RelativeLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fadingEdge="none"
        android:fillViewport="true" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#fff"
            android:orientation="vertical" >

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Button 1"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 2"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 3"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 4"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 5"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 6"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 7"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 8"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 9"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 10"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 11"
                android:textColor="@color/black" />

            <Button
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginTop="10dp"
                android:text="Button 12"
                android:textColor="@color/black" />
        </LinearLayout>
    </ScrollView>

</LinearLayout>
Essen answered 26/11, 2013 at 12:10 Comment(0)
P
7

Just change the LinearLayout inside the ScrollView

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top|center"
        android:background="#fff"
        android:orientation="vertical" >

Give the android:layout_gravity="top|center" instead of android:layout_gravity="center"

Hope it helps.

Pase answered 26/11, 2013 at 12:10 Comment(0)
R
3

This values helped me solve a similar problem: Set android:fillViewport="true" on the ScrollView and use android:gravity instead of android:layout_gravity on the ScrollView child, in my case a LinearLayout with all weights cleared.

Rhoads answered 17/2, 2014 at 14:4 Comment(0)
U
2

Try changing the parent layout to Linear. It might work. Don't know how and why, but for me it worked in a similar situation. Give it a try.

Uredium answered 26/11, 2013 at 12:7 Comment(0)
D
0

Give a top padding of 50dp

 <LinearLayout
            android:id="@+id/linearLayout"
            android:paddingTop="50dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />
Dichroite answered 11/12, 2020 at 12:58 Comment(1)
temporary solution, like "Jugaad"Mendoza
A
-1

use android:layout_gravity="center" in LinearLayout

Aubreir answered 27/4, 2016 at 12:15 Comment(0)
L
-1
it's work 100% 

 1. LinearLayout ->
    2. ScrollView-> 

<androidx.appcompat.widget.LinearLayoutCompat
    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="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context=".sales.CustomerDetailListActivity">
       <ScrollView
            android:id="@+id/layoutCard"
            app:layout_constraintTop_toBottomOf="@+id/subtitle_of_page"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="4dp"
            android:layout_marginLeft="4dp"
            android:fillViewport="false"
            android:fadingEdge="none">
</ScrollView>
</androidx.appcompat.widget.LinearLayoutCompat>
Lcm answered 30/3, 2022 at 15:26 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Daffie

© 2022 - 2024 — McMap. All rights reserved.