Jacksparrow
Jacksparrow

Reputation: 115

Adding view to bottom of layout in scrollview

So, i have a linear layout and a textview (both wrapped in scrollview). I want to place textview at bottom of screen initially (I DONT want it to be fixed at the bottom). I followed this question Adding view to bottom of layout inside a scrollview but it didn't help. Here's my layout. (all layout_width attribute is match_parent)

<ScrollView
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
    android:orientation="vertical"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_height="0dp"
        android:layout_weight="1">
        <!-- this expands to fill the empty space if needed -->
    </LinearLayout>

    <!-- this sits at the bottom of the ScrollView,
    getting pushed out of view if the ScrollView's
    content is tall enough -->
    <TextView
        android:layout_height="wrap_content"
        android:text="something">
    </TextView>
</LinearLayout>
</ScrollView>

The problem is the textview is never visible. Could you tell what I can do to fix it? (Initially there is enough space for linear layout and textview to fit in screen) PS: please dont mark as duplicate, as all other related questions want the textview to be FIXED at bottom.

Upvotes: 1

Views: 1055

Answers (2)

Nidhi Pandya
Nidhi Pandya

Reputation: 198

Try this.It may solve your problem

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <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:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="text1" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="text2" />


            </LinearLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="something"></TextView>
        </LinearLayout>

    </ScrollView>
</RelativeLayout>

Upvotes: 0

Shankar D
Shankar D

Reputation: 29

Try this one

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

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

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="something">
            </TextView>
        </LinearLayout>

    </ScrollView>

    <include
        layout="@layout/your_edit_text_layout_here"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom" />
</LinearLayout>

Upvotes: 1

Related Questions