上下文
在我的顶部标题中,我有一个按钮,让第二个TextView为View.Visible
或View.Gone
。我的ViewPager内容具有特定的大小来演示我的问题,可在Nexus 5上重现。
问题
当我打开我的应用程序并向上和向下滚动内容时,我没有任何问题。然后我隐藏了我的第二个文本视图
现在,如果我的手指从TextView(蓝色)或按钮(橙色)开始滚动,我就不能滚动了。但是,如果我的手指开始从白色背景滚动它是有效的。
在隐藏第二个文本上单击两次后(返回初始布局),当我滚动时,布局开始从底部开始近似显示在40dp(appBarSize)
测试
- 用EditText
或Button
替换View
或TextView
让我滚动左
- 在内容添加高度的底部添加虚拟视图,并且滚动是可能的
- 向内容添加更多大小与前一点相同
- 在NestedScrollView(第583行)中,onInterceptTouchEvent
ViewCompat.canScrollVertically(this,1)
在此特定高度的内容中返回false
/*
* Don't try to intercept touch if we can't scroll anyway.
*/
if (getScrollY() == 0 && !ViewCompat.canScrollVertically(this, 1)) {
return false;
}
不是那么类似的问题:
NestedScrollView not scrolling due to EditText
CollapsingToolBar not working with not so tall content
欢迎任何帮助:)
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>
MainActivity Class
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();
}
}
}