我无法向下滚动屏幕以查看“回复者:”部分中的数据。如何使我的布局可滚动?
答案 0 :(得分:178)
将所有内容包装在ScrollView
:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Here you put the rest of your current view-->
</ScrollView>
正如David Hedlund所说,ScrollView
只能包含一个项目...所以如果你有这样的东西:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- bla bla bla-->
</LinearLayout>
您必须将其更改为:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- bla bla bla-->
</LinearLayout>
</ScrollView>
答案 1 :(得分:35)
使用滚动视图和相对布局:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"> <!--IMPORTANT otherwise backgrnd img. will not fill the whole screen -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/background_image"
>
<!-- Bla Bla Bla i.e. Your Textviews/Buttons etc. -->
</RelativeLayout>
</ScrollView>
答案 2 :(得分:3)
将所有内容包装在ScrollView
中<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ruatech.sanikamal.justjava.MainActivity">
<!-- Here you put the rest of your current view-->
</ScrollView>
答案 3 :(得分:0)
If you even did not get scroll after doing what is written above .....
Set the android:layout_height="250dp"
or you can say xdp
where x
can be any numerical value.
答案 4 :(得分:0)
是的,这非常简单。只需将您的代码放入其中:
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
//YOUR CODE
</androidx.core.widget.NestedScrollView>