[英]Relative Layout does not scroll after adding 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"
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>
我已將recyclerview與數據列表連接在一起,但是為什么RecyclerView Layout可滾動但不能滾動整個Relativelayout。 我已經用ScrollView包裝了RelativeLayout。 似乎不起作用。 請看下面的圖片
讓我知道你們是否有更好的解決方案。 十億謝謝。
將您的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">
您已在另一個滾動組件中添加了一個滾動組件,即Scrollview中的RecycleView,因此只有一個組件會成為焦點。 這違反了Android准則。 您永遠不要將一個滾動組件放在另一個滾動組件中。 但是要實現兩個滾動
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.