1

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.

Community
  • 1
  • 1
Jacksparrow
  • 105
  • 1
  • 9
  • What part of this screen do you expect to scroll if the last item which is the TextView if placed to the bottom? – foxanna Dec 04 '16 at 18:41
  • I need the whole screen to scroll. I have edit texts in the linear layout, and when i click on them, the soft keyboard opens, hence i need scroll for the screen. The text view should be only INITIALLY at the bottom – Jacksparrow Dec 04 '16 at 18:44
  • Inflate the view from a layout file in your Activity.java file, and try using addView method on the scrollview. Not sure tho – Asym Dec 04 '16 at 19:05

2 Answers2

1

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>
Shankar D
  • 29
  • 7
0

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>
Nidhi Pandya
  • 198
  • 1
  • 8