Android ScrollView使其他项目位移。

huangapple go评论60阅读模式
英文:

Android ScrollView displaces other items

问题

I tried all decisions from https://stackoverflow.com/questions/14811032/scrollview-not-scrolling-at-all but my ScrollView doesn't work right yet.

我尝试了 https://stackoverflow.com/questions/14811032/scrollview-not-scrolling-at-all 中的所有解决方案,但我的 ScrollView 仍然无法正常工作。

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.

我尝试将 TextView 嵌套在 ScrollView 中,而不使用 LinearView,将 ScrollView 的 android:layout_height 设置为 0dp(在这种情况下根本不显示),尝试设置 fill_parent、match_parent 或 wrap_content 等多个值,删除和恢复 padding 值等等。

Here's my whole long code of the activity.

以下是我整个长代码的活动内容。

英文:

I tried all decisions from https://stackoverflow.com/questions/14811032/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...

答案1

得分: 0

我找到了决定。关键是仅为ScrollView设置android:layout_weight值。

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

请注意,我只翻译了XML中的文本内容,代码部分保持原样。

英文:

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

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
xmlns:tools=&quot;http://schemas.android.com/tools&quot;
android:layout_width=&quot;fill_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:gravity=&quot;top&quot;
android:orientation=&quot;vertical&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_gravity=&quot;top&quot;
android:weightSum=&quot;3&quot;
android:orientation=&quot;horizontal&quot;&gt;
&lt;RadioGroup
android:id=&quot;@+id/rgLearnRepeat&quot;
android:gravity=&quot;left&quot;
android:layout_weight=&quot;2&quot;
android:layout_width=&quot;0dp&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_marginLeft=&quot;12dp&quot;
android:layout_marginRight=&quot;0dp&quot;
android:orientation=&quot;horizontal&quot;&gt;
&lt;RadioButton
android:id=&quot;@+id/rbLearn&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:checked=&quot;true&quot;
android:text=&quot;@string/rbLearn_text&quot;
android:textColorLink=&quot;#00BCD4&quot; /&gt;
&lt;RadioButton
android:id=&quot;@+id/rbRepeat&quot;
android:text=&quot;@string/rbRepeat_text&quot;
android:layout_marginLeft=&quot;12dp&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot; /&gt;
&lt;/RadioGroup&gt;
&lt;Button
android:id=&quot;@+id/statButton&quot;
android:layout_width=&quot;0dp&quot;
android:onClick=&quot;onStatClick&quot;
android:layout_marginLeft=&quot;2dp&quot;
android:layout_marginRight=&quot;12dp&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_weight=&quot;1&quot;
android:text=&quot;@string/btStat_text&quot; /&gt;
&lt;/LinearLayout&gt;
&lt;TextView
android:id=&quot;@+id/tvWord&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:paddingTop=&quot;24dp&quot;
android:paddingLeft=&quot;12dp&quot;
android:paddingRight=&quot;12dp&quot;
android:paddingBottom=&quot;18dp&quot;
tools:text=&quot;@string/tvWord_text&quot;
android:textColor=&quot;#09627C&quot;
android:textSize=&quot;36dp&quot; /&gt;
&lt;ScrollView
android:layout_weight=&quot;4&quot;
android:layout_height=&quot;fill_parent&quot;
android:scrollbars=&quot;none&quot;
android:fillViewport=&quot;true&quot;
android:layout_width=&quot;match_parent&quot;&gt;
&lt;LinearLayout
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:paddingTop=&quot;18dp&quot;
android:paddingLeft=&quot;12dp&quot;
android:paddingRight=&quot;12dp&quot;
android:paddingBottom=&quot;24dp&quot;&gt;
&lt;TextView
android:id=&quot;@+id/tvTranslation&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;wrap_content&quot;
android:onClick=&quot;onSuggestionClick&quot;
tools:text=&quot;@string/tvTranslation_text&quot;
android:textColor=&quot;#635C5C&quot;
android:textSize=&quot;24dp&quot;
android:textStyle=&quot;italic&quot; /&gt;
&lt;/LinearLayout&gt;
&lt;/ScrollView&gt;
&lt;LinearLayout
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_gravity=&quot;center&quot;
android:orientation=&quot;horizontal&quot;&gt;
&lt;Button
android:id=&quot;@+id/btKnow&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:onClick=&quot;onKnowClick&quot;
android:layout_margin=&quot;10dp&quot;
android:text=&quot;@string/btKnow_text&quot; /&gt;
&lt;Button
android:id=&quot;@+id/btWillLearn&quot;
android:layout_width=&quot;wrap_content&quot;
android:layout_height=&quot;wrap_content&quot;
android:layout_margin=&quot;10dp&quot;
android:onClick=&quot;onWillLearnClick&quot;
android:text=&quot;@string/btWillLearn_text&quot; /&gt;
&lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;

huangapple
  • 本文由 发表于 2023年5月22日 17:32:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76304786.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定