简体   繁体   English

添加滚动视图后,相对布局不滚动

[英]Relative Layout does not scroll after adding scrollview

Good day. 美好的一天。 I have a layout code shown below 我有如下所示的布局代码

<?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"
    android:fillViewport="true" >

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        tools:context=".MainActivity">

        <include
            android:id="@+id/toolbar"
            layout="@layout/app_bar" />


        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="165dp"
            android:layout_below="@+id/toolbar" />

        <RelativeLayout
            android:id="@+id/relativeLayout"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:layout_alignBottom="@id/viewpager"
            android:background="#33000000">

            <TextView
                android:id="@+id/tv_image_description"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:paddingLeft="10dp"
                android:text="Shop Name"
                android:textColor="#FFF" />


            <LinearLayout
                android:id="@+id/ll_point_group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:orientation="horizontal"
                android:paddingRight="10dp">

            </LinearLayout>
        </RelativeLayout>


        <android.support.v7.widget.RecyclerView
            android:id="@+id/cardList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/relativeLayout" />


    </RelativeLayout>
</ScrollView>

I have connected my recyclerview with a list of data but why is RecyclerView Layout is scrollable but not the entire Relativelayout. 我已将recyclerview与数据列表连接在一起,但是为什么RecyclerView Layout可滚动但不能滚动整个Relativelayout。 I have wrapped the RelativeLayout with ScrollView. 我已经用ScrollView包装了RelativeLayout。 it seems like not working. 似乎不起作用。 please see the image below 请看下面的图片 这是布局的样子

Do let me know if you guys have better solution for this. 让我知道你们是否有更好的解决方案。 Billion thanks. 十亿谢谢。

Change your RelativeLayout height to wrap_content 将您的RelativeLayout高度更改为wrap_content

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    tools:context=".MainActivity">

You have added one scrolling component in another- RecycleView in a Scrollview So only one will take focus. 您已在另一个滚动组件中添加了一个滚动组件,即Scrollview中的RecycleView,因此只有一个组件会成为焦点。 This is against android guidelines. 这违反了Android准则。 you should never put one scrolling component in another. 您永远不要将一个滚动组件放在另一个滚动组件中。 However to achieve both scrolling 但是要实现两个滚动

yourRecycleView.setOnTouchListener(new OnTouchListener() {
    // Setting on Touch Listener for handling the touch inside ScrollView
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    // Disallow the touch request for parent scroll on touch of child view
    v.getParent().requestDisallowInterceptTouchEvent(true);
    return false;
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM