gpt4 book ai didi

android - 如何使父 View 和 subview 都可滚动

转载 作者:行者123 更新时间:2023-11-29 19:04:50 25 4
gpt4 key购买 nike

我有一个 View ,其中有 SpinnerLinearlayout诠释它。 Linearlayout作为子布局的父级。子布局以编程方式膨胀。 subview 有 CardViewTextViewCardView 中的 ListView .

我的问题是我想让整个 View (查看 SpinnerLinearLayout )可滚动,并且 subview 也是如此。但是每当我尝试在 CardView 中滚动 ListView 时,整个 View 滚动。当用户尝试滚动 ListView 时,我的子布局内的 View 应该只滚动。

这是我的父布局:

<?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="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">

<com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
android:id="@+id/shelfShareSelectionSpiiner"
android:layout_width="@dimen/_180sdp"
android:layout_height="@dimen/_40sdp"
android:layout_gravity="center"
android:hint="Select Category" />

<LinearLayout
android:id="@+id/shelfShareLinearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="@dimen/_5sdp"
android:layout_marginStart="@dimen/_5sdp"
android:padding="@dimen/_10sdp" />


</LinearLayout>
</ScrollView>

这是我的 child 观点:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
android:id="@+id/shelfShareMasterLL"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.CardView
android:id="@+id/frontalRodShareCardView"

android:layout_width="@dimen/_292sdp"
android:layout_height="@dimen/_250sdp"
android:layout_marginLeft="@dimen/_4sdp"
android:layout_marginRight="@dimen/_4sdp"
android:layout_marginStart="@dimen/_4sdp"
android:layout_marginTop="@dimen/_8sdp"
app:cardElevation="@dimen/_3sdp"
app:cardUseCompatPadding="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/shelfShareMasterRL"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/shelfShareHeadingTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginLeft="@dimen/_10sdp"
android:layout_marginTop="@dimen/_10sdp"
android:text="Frontal Rod Share"
android:textSize="@dimen/_10ssp" />


<ListView
android:id="@+id/shelfShareProductListView"
android:layout_width="match_parent"
android:layout_height="wrap_content">

</ListView>

</RelativeLayout>

</android.support.v7.widget.CardView>

</LinearLayout>

谢谢。

最佳答案

我认为要实现这一点,您需要为 listview 实现 ontouchListener。在这个监听器中,您需要防止父 ScrollView 触摸事件。

shelfShareProductListView.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;
}
});

关于android - 如何使父 View 和 subview 都可滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com