Amir Rachum
Amir Rachum

Reputation: 79615

Making a TextView expand without covering other views

I'm trying to implement a layout in android which consists of several TextViews and some buttons. I want one of the TextViews (which is a log of the game I'm implementing) to take up all available space it has, and be scrollable if there's too much text to display. However, I can't seem to get it to no overlay views below it when it expands - instead, it stop at the bottom of the screen:

enter image description here

In this screenshot, there's a "scoreboard" TextView, a "hand" TextView, a "log" TextView and a LinearLayout with several buttons. All TextViews have dynamic length, but the first two aren't supposed to take up more than a few lines. The Trouble is, that the log expands and covers the button below it (on the plus side, it is scrollable). Can you show me how to fix this?

Here's the layout XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/scoreboard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:text="Scoreboard" />

    <TextView
        android:id="@+id/handinfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/scoreboard"
        android:text="Hand" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_alignParentBottom="true" >

        <Button
            android:id="@+id/stay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:text="Stay" />

        <Button
            android:id="@+id/leave"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:text="Leave" />

        <Button
            android:id="@+id/pay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:text="Pay" />

        <Button
            android:id="@+id/payWithWild"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:text="Pay Wild" />

        <Button
            android:id="@+id/dontPay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:text="Don&apos;t Pay" />
    </LinearLayout>

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/handinfo" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/log"
            android:text="" />

    </ScrollView>



</RelativeLayout>

Upvotes: 2

Views: 1174

Answers (1)

waqaslam
waqaslam

Reputation: 68167

Add the following attributes to your ScrollView and it should fix the display:

android:layout_below="@id/handinfo"
android:layout_above="@id/linearLayout1"

Upvotes: 4

Related Questions