如何使我的布局能够向下滚动?

Pra*_*Raj 77 layout android

我无法向下滚动屏幕以查看"回复者:"部分中的数据.如何使我的布局可滚动?

替代文字

Cri*_*ian 182

只需将所有内容包装在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>
Run Code Online (Sandbox Code Playgroud)

正如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>
Run Code Online (Sandbox Code Playgroud)

您必须将其更改为:

<?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>
Run Code Online (Sandbox Code Playgroud)

  • +1.快速说明:`ScrollView`只能包含一个子节点,所以如果您目前获得的是很多视图,则需要将它们包装在一个视图组中(比如`LinearLayout`) (12认同)

Vin*_*ang 37

要使用滚动视图和相对布局:

<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>
Run Code Online (Sandbox Code Playgroud)