0

I tried all decisions from ScrollView not scrolling at all but my ScrollView doesn't work right yet.

I tried to nest the TextView inside the ScrollView without the LinearView, to set android:layout_height of the ScrollView to 0dp (not appearing at all in that case), to set several values of fill_parent, match_parent or wrap_content, to delete and restore the padding values and so on.

Here's my whole long code of the activity.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:weightSum="7"
    android:gravity="top"
    android:orientation="vertical">

    <LinearLayout
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:weightSum="3"
        android:orientation="horizontal">
        <RadioGroup
            android:id="@+id/rgLearnRepeat"
            android:gravity="left"
            android:layout_weight="2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="12dp"
            android:layout_marginRight="0dp"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/rbLearn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="@string/rbLearn_text"
                android:textColorLink="#00BCD4" />

            <RadioButton
                android:id="@+id/rbRepeat"
                android:text="@string/rbRepeat_text"
                android:layout_marginLeft="12dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </RadioGroup>

        <Button
            android:id="@+id/statButton"
            android:layout_width="0dp"
            android:onClick="onStatClick"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="12dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/btStat_text" />
    </LinearLayout>
    <TextView
        android:id="@+id/tvWord"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="24dp"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:paddingBottom="18dp"
        android:layout_weight="1"
        tools:text="@string/tvWord_text"
        android:textColor="#09627C"
        android:textSize="36dp" />

    <ScrollView
        android:layout_weight="0"
        android:layout_height="fill_parent"
        android:scrollbars="none"
        android:fillViewport="true"
        android:layout_width="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="18dp"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:paddingBottom="24dp">

            <TextView
                android:id="@+id/tvTranslation"
                android:layout_weight="3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="onSuggestionClick"
                tools:text="@string/tvTranslation_text"
                android:textColor="#635C5C"
                android:textSize="24dp"
                android:textStyle="italic" />
        </LinearLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btKnow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="onKnowClick"
            android:layout_margin="10dp"
            android:text="@string/btKnow_text" />

        <Button
            android:id="@+id/btWillLearn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:onClick="onWillLearnClick"
            android:text="@string/btWillLearn_text" />
    </LinearLayout>

</LinearLayout>

Please help...

  • You mixed up the weight. The smaller the number in 'android:layout_weight' the higher its priority. That means in your case the scroll view can grow as big as it wants and other items are moved to make space for it(since they have the higher weight value). Solution: Change the weight-value and give the scrollview the highest value/least priority so the other views can arrange themselves and the scrollview will grow to the rest of the space left. – Thommy May 22 '23 at 12:18
  • Thank you! So I had updated the values of android:layout_weight next way: Top LinearLayout - 1; TextView - 2; ScrollView - 4; Bottom LinearLayout - 3. Now I have working (hooray!) ScrollView, but top LinearLayout shrinks to very small size and TextView doesn't appear at all. What am I wrong in? – AstFreelancer May 22 '23 at 16:37
  • I found it! It turned out that you just need to remove all values of android:layout_weight except one for the ScrollView. – AstFreelancer May 22 '23 at 18:16

1 Answers1

0

So I found the decision. The point is to set android:layout_weight value only for the ScrollView.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:gravity="top"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:weightSum="3"
        android:orientation="horizontal">
        <RadioGroup
            android:id="@+id/rgLearnRepeat"
            android:gravity="left"
            android:layout_weight="2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="12dp"
            android:layout_marginRight="0dp"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/rbLearn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="@string/rbLearn_text"
                android:textColorLink="#00BCD4" />

            <RadioButton
                android:id="@+id/rbRepeat"
                android:text="@string/rbRepeat_text"
                android:layout_marginLeft="12dp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </RadioGroup>

        <Button
            android:id="@+id/statButton"
            android:layout_width="0dp"
            android:onClick="onStatClick"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="12dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/btStat_text" />
    </LinearLayout>
    <TextView
        android:id="@+id/tvWord"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="24dp"
        android:paddingLeft="12dp"
        android:paddingRight="12dp"
        android:paddingBottom="18dp"
        tools:text="@string/tvWord_text"
        android:textColor="#09627C"
        android:textSize="36dp" />

    <ScrollView
        android:layout_weight="4"
        android:layout_height="fill_parent"
        android:scrollbars="none"
        android:fillViewport="true"
        android:layout_width="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="18dp"
            android:paddingLeft="12dp"
            android:paddingRight="12dp"
            android:paddingBottom="24dp">

            <TextView
                android:id="@+id/tvTranslation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="onSuggestionClick"
                tools:text="@string/tvTranslation_text"
                android:textColor="#635C5C"
                android:textSize="24dp"
                android:textStyle="italic" />
        </LinearLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btKnow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:onClick="onKnowClick"
            android:layout_margin="10dp"
            android:text="@string/btKnow_text" />

        <Button
            android:id="@+id/btWillLearn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:onClick="onWillLearnClick"
            android:text="@string/btWillLearn_text" />
    </LinearLayout>

</LinearLayout>