nestedScrollview中的Scrollview与其他版本的android一起工作正常,但在kitkat中它无效。 我已将onItemClick()函数添加到nestedscrollview。点击嵌套滚动视图时,只有scrollview(父级)工作。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:padding="10dp"
>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/parentScrollview"
android:nestedScrollingEnabled="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/relative1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/navyBlue"
android:orientation="horizontal">
<ImageView
android:id="@+id/remarksLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/header_left_padding_size"
android:src="@drawable/ic_action_remarks_report_white"/>
<TextView
android:id="@+id/remarksTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/remarksLogo"
android:textColor="@color/white"
android:layout_marginRight="10dp"
android:gravity="center"
android:textSize="@dimen/header_text_size"
android:text=""
android:textStyle="bold"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="0dp"
android:paddingTop="10dp"
android:weightSum="6">
<TextView
android:id="@+id/datedTitles"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:textAlignment="center"
android:padding="5dp"
android:background="@color/navyBlue"
android:textColor="@color/white"
android:paddingLeft="5dp"
android:textSize="@dimen/sub_header_text_size"
android:text=""/>
<TextView
android:id="@+id/fromTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:padding="5dp"
android:background="@drawable/left_right_border_white"
android:textColor="@color/white"
android:paddingLeft="5dp"
android:textSize="@dimen/sub_header_text_size"
android:text=""/>
<TextView
android:id="@+id/detailsTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:padding="5dp"
android:background="@color/navyBlue"
android:textColor="@color/white"
android:paddingLeft="5dp"
android:textSize="@dimen/sub_header_text_size"
android:text=""/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:orientation="vertical"
android:layout_marginBottom="20dp">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="true"
android:id="@+id/childNestedScrollView"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical"
android:fadeScrollbars="false"
android:nestedScrollingEnabled="true"
android:fillViewport="true">
<com.iflytechsoft.studentsuccess.utils.studentsuccessutils.ListViewForEmbeddingInScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/remarksListView"
android:choiceMode="singleChoice"
android:background="@drawable/background_white_border_navyblue"
android:layout_marginBottom="20dp"
/>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="0dp"
android:id="@+id/announcementDetailLayout"
android:visibility="gone"
android:background="@color/navyBlue"
android:weightSum="6">
<TextView
android:id="@+id/dated"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:gravity="center"
android:background="@color/navyBlue"
android:textColor="@color/white"
android:paddingLeft="5dp"
android:textSize="@dimen/sub_header_text_size"
android:text=""/>
<TextView
android:id="@+id/from"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="@drawable/left_right_border_white"
android:textColor="@color/white"
android:paddingLeft="5dp"
android:textSize="@dimen/sub_header_text_size"
android:text=""/>
<TextView
android:id="@+id/subject"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3.7"
android:background="@color/navyBlue"
android:textColor="@color/white"
android:paddingLeft="5dp"
android:textSize="@dimen/sub_header_text_size"
android:text=""/>
</LinearLayout>
<ir.noghteh.JustifiedTextView xmlns:noghteh="http://noghteh.ir"
android:id="@+id/details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:paddingLeft="5dp"
noghteh:textSize="@dimen/sub_header_text_size"
android:background="@drawable/background_white_border_navyblue"
/>
</LinearLayout>
</ScrollView>
</LinearLayout>
答案 0 :(得分:0)
试试这个
NestedScrollView view = (NestedScrollView) findviewbyid(R.id.childNestedScrollView);
view.setOnTouchListener(new ListView.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
// Handle ListView touch events.
v.onTouchEvent(event);
return true;
}
});
希望它会对你有所帮助。