androidandroid-linearlayouttextviewandroid-scroll

Scrollview in two Linearlayouts?


I have 4 TextViews in my Activity and i am using LinearLayout with vertical orientation. Top one TextView is kind of header (no need to scroll) next one is some kind of description which i want to make scrollable. 3rd one is again a heading (no scroll needed) and 4th is description (need to scroll). I tried but only top TextView (header) and 2nd TextView (description) is being showed on the screen. Description is scrollable but the problem is, other two TextView are hidden. Its kind of silly question to ask but i am kind of stuck here because i am new to android. Here is my xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?android:attr/actionBarSize"
android:orientation="vertical"
android:padding="15dp"

>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#d0f7c9"
    android:orientation="vertical"
    android:padding="10dp"

    >

    <TextView
        android:id="@+id/tvTitle"
        style="?android:attr/listSeparatorTextViewStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="#ffffff"
        android:textSize="20dp" />

</LinearLayout>


<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#b3cff4"
        android:orientation="vertical">

        <TextView
            android:id="@+id/tvShow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:textSize="20dp" />
    </LinearLayout>
</ScrollView>


<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Program Output"
    android:textColor="@color/black"
    android:textSize="25dp" />


<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#d2b3f4">

        <TextView
            android:id="@+id/tvOutput"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#ffffff"
            android:textSize="20dp" />

    </LinearLayout>

</ScrollView>


Solution

  • You can try like this,

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:orientation="vertical"
                  android:weightSum="2">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="#d0f7c9"
            android:orientation="vertical">
    
            <TextView
                android:id="@+id/tvTitle"
                style="?android:attr/listSeparatorTextViewStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Top Title"
                android:textColor="#ffffff"
                android:textSize="20dp"/>
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#b3cff4">
    
                <TextView
                    android:id="@+id/tvShow"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textSize="20dp"/>
            </ScrollView>
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">
    
            <TextView
                android:id="@+id/tvTitle1"
                style="?android:attr/listSeparatorTextViewStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="Seconf Title"
                android:textColor="#ffffff"
                android:textSize="20dp"/>
    
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#b3cff4">
    
                <TextView
                    android:id="@+id/tvShow1"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:textSize="20dp"/>
            </ScrollView>
        </LinearLayout>
    
    </LinearLayout>