2

I want a sticky TextView above a ScrollView:

The text view should cover 50% of the screen so I set the textview's and the inner linear layout's weight to "1".

But the TextView is not shown at all and the ScrollView is not scrolling!

any help would be greatly appreciated!

<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"
    android:background="#000000"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/wallbg"
        android:gravity="bottom"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:height="0dp"
            android:text="Some Text!"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="@android:color/white"
            android:textSize="50sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/wallbg"
            android:gravity="bottom"
            android:orientation="vertical" >

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true" >

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

                    <Button
                        android:id="@+id/btn1"
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="10dp"
                        android:background="@drawable/btnbg"
                        android:text="Some Text!"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/font_size" />

                    <Button
                        android:id="@+id/btn4"
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="10dp"
                        android:background="@drawable/btnbg"
                        android:text="Some Text!"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/font_size" />

                    <Button
                        android:id="@+id/btn2"
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="10dp"
                        android:background="@drawable/btnbg"
                        android:text="Some Text!"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/font_size" />

                    <Button
                        android:id="@+id/btn3"
                        android:layout_width="200dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="10dp"
                        android:background="@drawable/btnbg"
                        android:text="Some Text!"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/font_size" />
                </LinearLayout>
            </ScrollView>
        </LinearLayout>
    </LinearLayout>

</RelativeLayout>

1 Answer 1

2

It doesn't look like you need your RelativeLayout at all. Just make your outer LinearLayout the root view and set its layout_height property to match_parent (which is the main issue). Also, the LinearLayout inside the ScrollView should have wrap_content for its layout_height.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.