Android 滚动视图不会一直向下滚动
Android scroll view does not scroll all the way down
我看了很多问题,但是 none 列出的解决方案解决了我的问题:Scrollview doesn't scroll to the margin at the bottom
ScrollView doesn't scroll to the bottom
(Android) ScrollView won't scroll all the way to the bottom of my LinearLayout
我有一个具有以下布局的应用程序,它在 ScrollView 中包含一个 LinearLayout
<ScrollView android:id="@+id/Scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:padding="8dp"
android:id="@+id/tvPowersLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Powers"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:padding="8dp"
android:id="@+id/tvPowers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:text="Placeholder for powers"
/>
<TextView
android:padding="8dp"
android:textSize="20dp"
android:textStyle="bold"
android:text="Abilities"
android:id="@+id/tvAbilitiesLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:padding="8dp"
android:id="@+id/tvAbilities"
android:layout_width="wrap_content"
android:text="placeholder for abilities"
android:layout_height="wrap_content"
android:textSize="12dp"
/>
</LinearLayout>
</ScrollView>
基本上,此布局用于 Fragment。在该片段中,我为 tvPowers 和 tvAbilities 调用了 settext,其中的字符串是我从网站查询得到的。
这是一个片段
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scrollview,container,false);;
TextView tvPowers = (TextView) view.findViewById(R.id.tvPowers);
TextView tvAbilities = (TextView) view.findViewById(R.id.tvAbilities);
tvPowers.setText(Html.fromHtml(powers).toString());
tvAbilities.setText(Html.fromHtml(abilities).toString());
return view;
}
这是我的滚动视图没有一直向下滚动的屏幕截图
Picture
我曾尝试将 ScrollView 的宽度和高度搞乱为 match_parent 和 wrap_content。我还在 true 和 false 之间切换了 fillViewPort。我去掉了元素的所有填充,但仍然遇到同样的问题。
我遇到了同样的问题,这个解决方案对我有用:
而不是 ScrollView
使用 NestedScrollView
查看对我有帮助的answer。
我看了很多问题,但是 none 列出的解决方案解决了我的问题:Scrollview doesn't scroll to the margin at the bottom
ScrollView doesn't scroll to the bottom
(Android) ScrollView won't scroll all the way to the bottom of my LinearLayout
我有一个具有以下布局的应用程序,它在 ScrollView 中包含一个 LinearLayout
<ScrollView android:id="@+id/Scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:padding="8dp"
android:id="@+id/tvPowersLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Powers"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:padding="8dp"
android:id="@+id/tvPowers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:text="Placeholder for powers"
/>
<TextView
android:padding="8dp"
android:textSize="20dp"
android:textStyle="bold"
android:text="Abilities"
android:id="@+id/tvAbilitiesLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:padding="8dp"
android:id="@+id/tvAbilities"
android:layout_width="wrap_content"
android:text="placeholder for abilities"
android:layout_height="wrap_content"
android:textSize="12dp"
/>
</LinearLayout>
</ScrollView>
基本上,此布局用于 Fragment。在该片段中,我为 tvPowers 和 tvAbilities 调用了 settext,其中的字符串是我从网站查询得到的。
这是一个片段
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.scrollview,container,false);;
TextView tvPowers = (TextView) view.findViewById(R.id.tvPowers);
TextView tvAbilities = (TextView) view.findViewById(R.id.tvAbilities);
tvPowers.setText(Html.fromHtml(powers).toString());
tvAbilities.setText(Html.fromHtml(abilities).toString());
return view;
}
这是我的滚动视图没有一直向下滚动的屏幕截图 Picture
我曾尝试将 ScrollView 的宽度和高度搞乱为 match_parent 和 wrap_content。我还在 true 和 false 之间切换了 fillViewPort。我去掉了元素的所有填充,但仍然遇到同样的问题。
我遇到了同样的问题,这个解决方案对我有用:
而不是 ScrollView
使用 NestedScrollView
查看对我有帮助的answer。