Siddharth
Siddharth

Reputation: 9574

How to overflow views to the next row, instead of disappearing into the unknown

I am trying to fit TextViews in the screen, so that every textview contains 1 word of a long sentence.

This is a very long sentence, so long that it does not fit in the screen.

Here fit in the screen are 4 textviews, which I need to move to the next line. Basically, this way I can get click events for each word (since I need to support Android 2.2, and Spannable needs getX and getY that 2.2 does not support).

Layout

         <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:fitsSystemWindows="true"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/word1"
                style="@style/select_part_of_speech_word" />

            <TextView
                android:id="@+id/word2"
                style="@style/select_part_of_speech_word" />
..... more TextViews.....
            <TextView
                android:id="@+id/word15"
                style="@style/select_part_of_speech_word" />
        </LinearLayout>

Style applied

<style name="select_part_of_speech_word" parent="@android:style/TextAppearance.Medium">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_marginBottom">10dp</item>
    <item name="android:layout_marginTop">10dp</item>
    <item name="android:text">@string/randomTutorialText</item>
    <item name="android:textColor">@android:color/black</item>
    <item name="android:textSize">25sp</item>
    <item name="android:visibility">visible</item>
    <item name="android:lines">1</item>
</style>

With this, the textviews just seem to disappear. I guess if I use a horizontal scrollview, I will be able to view all 15 textviews, but I need them to overflow to the next available space below. Can this be done ?

Upvotes: 0

Views: 86

Answers (1)

Benito Bertoli
Benito Bertoli

Reputation: 25793

So you want something equivalent to a FlowLayout.

You could try Romain Guy's implementation.

Upvotes: 1

Related Questions