Android: ScrollView 中的相对布局

标签 android android-layout android-scrollview android-relativelayout

我有一个带有多个 ImageViewRelativeLayout,当我转动屏幕时,ImageView 变得杂乱无章。所以我决定把它包装成一个ScrollView。但是 ScrollView 不起作用!

谁能帮我解决这个问题?我知道正确的方法是设计一个GridViewListView,但是由于我有一些问题没有人回答我,所以我决定走这条路。

这是我的 xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:scrollbars="none" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/continuePizza"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="continue" />

    <Button
        android:id="@+id/finishP"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/continuePizza"
        android:layout_alignParentLeft="true"
        android:text="finish" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="16dp"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageView1"
        android:layout_marginLeft="18dp"
        android:layout_toRightOf="@+id/imageView1"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_marginTop="18dp"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView3"
        android:layout_centerVertical="true"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/imageView3"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView5"
        android:layout_marginTop="17dp"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView2"
        android:layout_alignTop="@+id/imageView5"
        android:layout_marginLeft="10dp"
        android:src="@drawable/download" />

    <ImageView
        android:id="@+id/imageView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView7"
        android:layout_alignTop="@+id/imageView3"
        android:src="@drawable/download" />

</RelativeLayout>
</ScrollView>

最佳答案

简单的解决方案,只需将 android:fillViewport="true"添加到 Scrollview 即可:

<ScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

<RelativeLayout ....... />

</ScrollView>

关于Android: ScrollView 中的相对布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18677421/

相关文章:

android - 在 Meteor 上进行 Junit 测试,Android-DDP 库

java - 调用JAWBONE API的JSON结果中存在问题

android - Android 中的文本观察器

android - 滚动子项(RecyclerView)时停止父项(NestedScrollview)的滚动

android - 我应该选择 Recyclerview 或 ScrollView 哪个?

android - ViewPager 不会与 FragmentPagerAdapter 滑动

android - 找不到以下类 : android. support.constraint.RelativeLayout

android - 使用 kotlin 的带圆角的 Imageview

Android 布局作为具有可选功能的按钮

Android父级onTouchEvent劫持子级onTouchEvent