NestedScrollView canScrollVertically returns false for content of a certain size

Context
In my top header, I have a button that allows the second TextView to be View.Visible or View.Gone . My ViewPager content has a specific size to demonstrate my problem reproducible on Nexus 5.

Problem
When I open the application and browse the content, I have no problem. Then I hide my second text.
Now I can no longer scroll if my finger launches scrolls from TextView (blue) or Button (orange). However, if my finger starts to scroll from a white background, it works.

enter image description here

After double-clicking on the second hide text (back to the original layout), when I scroll, the layout will start appearing about 40dp from the bottom (appBarSize)

enter image description here

Tested
- Replacing EditText or Button with View or TextView , let me scroll the page - Adding a dummy view at the bottom of the content, you can add height and scroll

- Adding a larger size to the content is similar to the previous paragraph. - In NestedScrollView (line 583) onInterceptTouchEvent ViewCompat.canScrollVertically(this,1) returns false in this particular content size increase

 /* * Don't try to intercept touch if we can't scroll anyway. */ if (getScrollY() == 0 && !ViewCompat.canScrollVertically(this, 1)) { return false; } 

Not so similar problems:
NestedScrollView not scrolling due to EditText
CollapsingToolBar does not work with not so high content

Any help is appreciated :)

Full Code Project (on Dropbox)

Layoutfile

 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:id="@+id/activity_main_header_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#aaeeee" android:descendantFocusability="beforeDescendants" android:focusableInTouchMode="true"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" app:layout_scrollFlags="scroll|enterAlways"> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:hint="first text" android:layout_weight="1"/> <Button android:id="@+id/hide_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:enabled="true" android:text="Hide second Text" android:layout_weight="0"/> <EditText android:id="@+id/second_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:hint="Second Text" android:layout_marginTop="30dp" android:layout_marginBottom="20dp"/> </LinearLayout> <android.support.design.widget.TabLayout android:id="@+id/activity_main_tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#cce8787c" app:tabGravity="fill" app:tabMode="fixed"/> </android.support.design.widget.AppBarLayout> <android.support.v4.view.ViewPager android:id="@+id/activity_main_content_viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:tag="No Scrollable" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <EditText android:layout_width="match_parent" android:layout_height="215dp" android:layout_margin="20dp" android:background="@android:color/holo_blue_bright" android:text="First case" tools:background="#456456" tools:ignore="MissingPrefix"/> <Button android:layout_width="match_parent" android:layout_height="215dp" android:layout_margin="20dp" android:text="Second case" android:background="@android:color/holo_orange_dark"/> </LinearLayout> </android.support.v4.widget.NestedScrollView> </android.support.v4.view.ViewPager> </android.support.design.widget.CoordinatorLayout> 

Class MainActivity

 public class MainActivity extends AppCompatActivity { private ViewPager viewPagerContent; private TabLayout tabLayout; private EditText whereText; private Button SearchButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.viewPagerContent = (ViewPager) findViewById(R.id.activity_main_content_viewpager); this.viewPagerContent.setAdapter(new MainContentPagerAdapter()); this.tabLayout = (TabLayout) findViewById(R.id.activity_main_tab_layout); tabLayout.setupWithViewPager(viewPagerContent); this.whereText = (EditText) findViewById(R.id.second_text); this.SearchButton = (Button) findViewById(R.id.hide_btn); this.SearchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { whereText.setVisibility( whereText.getVisibility() == View.VISIBLE? View.GONE : View.VISIBLE); } }); } [...] private class MainContentPagerAdapter extends PagerAdapter { @Override public Object instantiateItem(ViewGroup container, int position) { return container.getChildAt(position); } @Override public void destroyItem(ViewGroup container, int position, Object object) { } @Override public int getCount() { return viewPagerContent.getChildCount(); } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public CharSequence getPageTitle(int position) { return (CharSequence) viewPagerContent.getChildAt(position).getTag(); } } } 
+5
source share

All Articles