英文:
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.
<?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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论