如何在android活动的nestedscrollview中禁用viewpager的嵌套滚动?
现在的问题是,左右滑动recyclerviews片段的viewpager并没有随着nestedscrollview向下滚动。活动仅滚动到选项卡布局,如第二张图所示。Viewpager滚动嵌套。你能解决这个问题吗 以下是我的主要活动的布局:如何在android活动的nestedscrollview中禁用viewpager的嵌套滚动?,android,Android,现在的问题是,左右滑动recyclerviews片段的viewpager并没有随着nestedscrollview向下滚动。活动仅滚动到选项卡布局,如第二张图所示。Viewpager滚动嵌套。你能解决这个问题吗 以下是我的主要活动的布局: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas
<?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"
android:layout_height="match_parent"
android:id="@+id/main_profile"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="430dp"
android:id="@+id/app_bar"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/collapsing_toolbar"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/profile_image"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
android:src="@drawable/sample_image"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="240dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="William Stevenson"
android:textSize="24sp"
android:gravity="center"
android:textColor="#f0f0f0"
android:id="@+id/userName" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Graphic Designer. Freelancer"
android:textSize="16sp"
android:gravity="center"
android:textColor="#f0f0f0"
android:layout_below="@id/userName"
android:id="@+id/tagline"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_below="@id/tagline"
android:layout_marginTop="48dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<Button
android:layout_width="wrap_content"
android:layout_height="48dp"
android:paddingLeft="48dp"
android:paddingRight="48dp"
android:textSize="12sp"
android:textColor="#f0f0f0"
android:text="Follow"
android:layout_centerHorizontal="true"
android:id="@+id/follow"
android:background="@drawable/follow_button_flat"/>
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toLeftOf="@id/follow"
android:layout_centerVertical="true"
android:id="@+id/voiceCallMessage"
android:src="@drawable/ic_mic_none_white_48dp"
android:layout_marginRight="32dp" />
<ImageView
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_toRightOf="@id/follow"
android:layout_centerVertical="true"
android:id="@+id/videoCallMessage"
android:layout_marginLeft="32dp"
android:src="@drawable/ic_videocam_white_48dp" />
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:rippleColor="#303030"
app:backgroundTint="#3292D3"
app:layout_anchor="@id/app_bar"
android:src="@drawable/ic_bubble_chart_white_48dp"
app:fabSize="normal"
app:layout_anchorGravity="bottom|right"/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/nestedScrollView">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
android:id="@+id/profileStats"
android:orientation="horizontal">
...
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="256dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="48dp"
android:id="@+id/imagesAndVideos"
android:layout_below="@id/profileStats">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/frame_layout_corner"
android:clickable="false">
...
</TableLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="800+ Images"
android:layout_gravity="center"
android:gravity="center"
android:textColor="#f0f0f0"
android:id="@+id/imagesTag"
android:textSize="18sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="32dp"
android:paddingLeft="32dp"
android:paddingRight="32dp"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:text="Show All"
android:gravity="center"
android:id="@+id/showAll"
android:background="@drawable/follow_button_flat"
android:textColor="#f0f0f0"
android:textSize="14sp"/>
</LinearLayout>
</FrameLayout>
<com.gigamole.navigationtabstrip.NavigationTabStrip
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"
app:nts_animation_duration="300"
app:nts_factor="1.2"
app:nts_size="16dp"
app:nts_type="line"
app:nts_titles="@array/posts_and_friends"
android:layout_below="@id/imagesAndVideos"
android:layout_marginTop="48dp"
android:id="@+id/post_and_friends_nav_strip"/>
<!--Problem is here-->
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/posts_friends_view_pager"
android:layout_below="@id/post_and_friends_nav_strip"
android:layout_marginTop="16dp"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
public class Profile extends AppCompatActivity {
TextView userName, tagline, followers, followersTag, points, pointsTag, following, followingTag, imagesTag;
ImageView userImage, sample1, sample2, sample3, sample4;
Button showAllImages;
Typeface robotoRegular, robotoLight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_profile);
initActivity();
ViewPager postsAndFriendsViewPager = (ViewPager) findViewById(R.id.posts_friends_view_pager);
FragmentManager fragmentManager = getSupportFragmentManager();
ViewPagerAdapterPostsFriends viewPagerAdapterPostsFriends = new ViewPagerAdapterPostsFriends(fragmentManager);
postsAndFriendsViewPager.setAdapter(viewPagerAdapterPostsFriends);
NavigationTabStrip navigationTabStrip = (NavigationTabStrip) findViewById(R.id.post_and_friends_nav_strip);
navigationTabStrip.setTabIndex(0);
navigationTabStrip.setStripColor(Color.TRANSPARENT);
navigationTabStrip.setActiveColor(Color.RED);
navigationTabStrip.setInactiveColor(Color.DKGRAY);
navigationTabStrip.setViewPager(postsAndFriendsViewPager);
}
class ViewPagerAdapterPostsFriends extends FragmentStatePagerAdapter
{
ViewPagerAdapterPostsFriends(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
if(position == 0)
return Posts.init();
return ProfileFriends.init();
}
@Override
public int getCount() {
return 2;
}
}
private void initActivity()
{
userImage = (ImageView) findViewById(R.id.profile_image);
sample1 = (ImageView) findViewById(R.id.sample1);
sample2 = (ImageView) findViewById(R.id.sample2);
sample3 = (ImageView) findViewById(R.id.sample3);
sample4 = (ImageView) findViewById(R.id.sample4);
userName = (TextView) findViewById(R.id.userName);
imagesTag = (TextView) findViewById(R.id.imagesTag);
tagline = (TextView) findViewById(R.id.tagline);
points = (TextView) findViewById(R.id.points);
pointsTag = (TextView) findViewById(R.id.pointsTag);
followers = (TextView) findViewById(R.id.followers);
followersTag = (TextView) findViewById(R.id.followersTag);
following = (TextView) findViewById(R.id.following);
followingTag = (TextView) findViewById(R.id.followingTag);
showAllImages = (Button) findViewById(R.id.showAll);
robotoLight = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
robotoRegular = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
Picasso.with(this).load(R.drawable.sample_image).transform(new BrightnessFilterTransformation(this, -0.1f)).into(userImage);
userName.setTypeface(robotoLight);
imagesTag.setTypeface(robotoLight);
tagline.setTypeface(robotoLight);
points.setTypeface(robotoRegular);
pointsTag.setTypeface(robotoRegular);
followers.setTypeface(robotoRegular);
followersTag.setTypeface(robotoRegular);
following.setTypeface(robotoRegular);
followingTag.setTypeface(robotoRegular);
showAllImages.setTypeface(robotoLight);
}
}
根据我的经验,不建议使用嵌套滚动视图,因为它可能会混淆android事件处理程序,如果您也显示java代码,则会更有帮助我在问题中添加了java代码。那么,我应该用什么来代替nestedscrollview呢?如果将nestedscrollview更改为ScrollView,则可以缓慢滚动
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/friends"
android:layout_height="wrap_content"/>
public class Profile extends AppCompatActivity {
TextView userName, tagline, followers, followersTag, points, pointsTag, following, followingTag, imagesTag;
ImageView userImage, sample1, sample2, sample3, sample4;
Button showAllImages;
Typeface robotoRegular, robotoLight;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_profile);
initActivity();
ViewPager postsAndFriendsViewPager = (ViewPager) findViewById(R.id.posts_friends_view_pager);
FragmentManager fragmentManager = getSupportFragmentManager();
ViewPagerAdapterPostsFriends viewPagerAdapterPostsFriends = new ViewPagerAdapterPostsFriends(fragmentManager);
postsAndFriendsViewPager.setAdapter(viewPagerAdapterPostsFriends);
NavigationTabStrip navigationTabStrip = (NavigationTabStrip) findViewById(R.id.post_and_friends_nav_strip);
navigationTabStrip.setTabIndex(0);
navigationTabStrip.setStripColor(Color.TRANSPARENT);
navigationTabStrip.setActiveColor(Color.RED);
navigationTabStrip.setInactiveColor(Color.DKGRAY);
navigationTabStrip.setViewPager(postsAndFriendsViewPager);
}
class ViewPagerAdapterPostsFriends extends FragmentStatePagerAdapter
{
ViewPagerAdapterPostsFriends(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
if(position == 0)
return Posts.init();
return ProfileFriends.init();
}
@Override
public int getCount() {
return 2;
}
}
private void initActivity()
{
userImage = (ImageView) findViewById(R.id.profile_image);
sample1 = (ImageView) findViewById(R.id.sample1);
sample2 = (ImageView) findViewById(R.id.sample2);
sample3 = (ImageView) findViewById(R.id.sample3);
sample4 = (ImageView) findViewById(R.id.sample4);
userName = (TextView) findViewById(R.id.userName);
imagesTag = (TextView) findViewById(R.id.imagesTag);
tagline = (TextView) findViewById(R.id.tagline);
points = (TextView) findViewById(R.id.points);
pointsTag = (TextView) findViewById(R.id.pointsTag);
followers = (TextView) findViewById(R.id.followers);
followersTag = (TextView) findViewById(R.id.followersTag);
following = (TextView) findViewById(R.id.following);
followingTag = (TextView) findViewById(R.id.followingTag);
showAllImages = (Button) findViewById(R.id.showAll);
robotoLight = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Light.ttf");
robotoRegular = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Regular.ttf");
Picasso.with(this).load(R.drawable.sample_image).transform(new BrightnessFilterTransformation(this, -0.1f)).into(userImage);
userName.setTypeface(robotoLight);
imagesTag.setTypeface(robotoLight);
tagline.setTypeface(robotoLight);
points.setTypeface(robotoRegular);
pointsTag.setTypeface(robotoRegular);
followers.setTypeface(robotoRegular);
followersTag.setTypeface(robotoRegular);
following.setTypeface(robotoRegular);
followingTag.setTypeface(robotoRegular);
showAllImages.setTypeface(robotoLight);
}
}