androidscrollviewandroid-linearlayout

Android ScrollView displaces other items


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...


Solution

  • 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>