Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple textviews in a scrollview

Tags:

android

I have an activity which is displaying walking directions as text. I have a group of TextViews, 5 contain "Step x" where x is the step number and 5 more TextViews which contain the actual instructions.

The problem is that the last TextView goes of screen so I want to have the group of TextViews scroll as if they're one. Is this possible? I know ScrollView seems to only take one TextView as a child.

I was thinking of having all the text in one TextView however I would not be able to apply styling to the "Step x" text individually.

like image 722
sam Avatar asked Nov 30 '22 07:11

sam


2 Answers

You can just put all your text views into a LinearLayout and then put that layout into the ScrollView.

like image 68
Chris Avatar answered Dec 15 '22 02:12

Chris


Here's how I'd do it:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" 
android:scrollbars="horizontal" android:id="@+id/ScrollView">

<LinearLayout
        android:layout_width="fill_parent"                      
        android:orientation="vertical"
        android:id="@+id/linearLayout1" 
        android:layout_height="fill_parent"  
        android:layout_gravity="center_vertical|center_horizontal">

    <TextView android:text="@string/textView1" 
        android:id="@+id/textView1" 
        android:layout_width="280dip" 
        android:layout_height="60dip">
    </TextView>

    <TextView android:text="@string/textView2"
        android:id="@+id/textView2" 
        android:layout_width="280dip" 
        android:layout_height="60dip">
    </TextView>

    <TextView android:text="@string/textView3" 
        android:id="@+id/textView3" 
        android:layout_width="280dip" 
        android:layout_height="60dip">
    </TextView>

    <TextView android:text="@string/textView4"
        android:id="@+id/textView4" 
        android:layout_width="280dip" 
        android:layout_height="60dip">
    </TextView>


</LinearLayout>
</ScrollView>
like image 34
Chris Cashwell Avatar answered Dec 15 '22 01:12

Chris Cashwell