0

I'm trying to get TextView to wrap according to the device screensize so that the 3 button at the bottom will always be visible at the bottom of screen.

The layout I'm trying to get

I've tried the solution from here but the ScrollView doesn't seem to work. The 3 buttons is not visible.

The bad layout I'm getting :(

Here are my code. Thanks for reading.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:fillViewport="true">
        <TextView
            android:text="@string/default_tnc"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"     
            android:layout_weight="1.0"/>
    </ScrollView>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_alignParentBottom="true">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button 1"/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button 2"/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Button 3"/>
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>
Community
  • 1
  • 1
Short answer
  • 124
  • 7

4 Answers4

0

Add android:layout_weight="1" to your ScrollView and change height of ScrollView to 0
Remove android:layout_weight="1" from your TextView

<ScrollView
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:scrollbars="vertical"
            android:layout_weight="1.0"
            android:fillViewport="true">
            <TextView
                android:text="@string/default_tnc"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" // or wrap_content     
                />
  </ScrollView>

Hope this help

Linh
  • 43,513
  • 18
  • 206
  • 227
0

this is what you need , just copy and paste

   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<ScrollView
    android:id="@+id/scroll_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"
    android:layout_above="@+id/ll_layout"
    android:padding="10dp"
    android:layout_weight=".8">
    <TextView
        android:text="@string/temp_txt"
        android:textColor="@android:color/black"
        android:background="@android:color/white"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30dp"
        />
   </ScrollView>


    <LinearLayout
        android:layout_width="match_parent"
        android:id="@+id/ll_layout"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_alignParentBottom="true">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:layout_weight="1"
            android:text="Button 1"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="20dp"
            android:layout_weight="1"
            android:text="Button 2"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textSize="20dp"
            android:text="Button 3"/>
    </LinearLayout>
</RelativeLayout>
vabhi vab
  • 429
  • 4
  • 10
0

You can RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".lActivity">

<ScrollView
    android:id="@+id/web_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<TextView 
// enter code here
/>
</CrollView>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_alignParentBottom="true"
    android:background="#FFFFFF">

  <Button>
  <Button>
  <Button>

</RelativeLayout>

</RelativeLayout>
Thang BA
  • 162
  • 2
  • 12
0

Instead of using a LinearLayout as the main parent, Just use a RelativeLayout. Then just use the layout_above attribute in the ScrollView to have it set to be above the .

ativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/id_rl_below"
        android:layout_alignParentTop="true"
        android:scrollbars="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1.0"
            android:text="asdhgfahgdsashgaweatlweiutnwaueytluwae ytbluwae ytbluewzybltuewzsyb tzsydgzlu ybeutzybwlutvybwelutyvzewuiybtuwzey btuzwey tluiwg usdbugdslyuggjzsg zsdg sd mgzsdnzsntzsetxseyuxtrutfru xtfrunftu nxut uctr mxr untrxuxdumtrrumxrtmuxrumnrxtumn"
            android:textSize="50dp" />

    </ScrollView>

    <LinearLayout
        android:id="@id/id_rl_below"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 1" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 2" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 3" />

    </LinearLayout>

</RelativeLayout>

To know more about how to use RelativeLayouts. You can check the Official Android Developers Site -- RelativeLayout.LayoutParams. Hope this helps. :)

AL.
  • 33,241
  • 9
  • 119
  • 257