2017-02-14 100 views
0

我有一个VerticalScrollView里面的Horizo​​ntalScrollView。如果我滚动水平,滚动是平稳的。但是,如果我垂直滚动,滚动不平滑,有时滚动水平。如何使垂直滚动顺畅?Horizo​​ntalScrollView里面的ScrollView android

这里是我的XML,

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.sasank.calendarview.MainActivity" 
    android:background="@android:color/white"> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello World!" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="500dp" 
     android:layout_marginLeft="200dp" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="20dp"> 
     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical"> 
      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 
       <android.support.v7.widget.RecyclerView 
        android:id="@+id/chapter_list" 
        android:layout_width="150dp" 
        android:layout_height="match_parent"> 

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

       <HorizontalScrollView 
        android:id="@+id/horizontal_scroll" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_toRightOf="@id/chapter_list" 
        android:scrollbars="horizontal"> 
        <android.support.v7.widget.RecyclerView 
         android:id="@+id/calendar" 
         android:layout_width="wrap_content" 
         android:layout_height="match_parent"> 

        </android.support.v7.widget.RecyclerView> 
       </HorizontalScrollView> 

      </RelativeLayout> 
     </ScrollView> 

    </RelativeLayout> 
</RelativeLayout> 

即时通讯使用垂直LinearLayoutManager为Chapter_list Recyclerview和GridLayoutManager日历RecyclerView连接到嵌套滚动

+0

不知道它是否已经被固定,但滚动型的嵌套不支持或推荐。出于这个原因,我不得不建立一个自定义日历。 – samosaris

回答

2
android:nestedScrollingEnabled="true" 

你可以试试这个,但仍存在问题和等等其实很普遍。人们在这里对StackOverflow的同样的问题,看一看,我希望它可以帮助你:Problems with Nested Scrolling

+0

试过了,但没有奏效 –

0

我有垂直滚动视图和水平recycleview照片库在我的项目之一,它工作正常。下面的代码:

片段/活动布局:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     ... 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/horizontal_recycler_view" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="15dp" 
     android:layout_marginBottom="15dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:horizontalSpacing="10dp" 
     android:isScrollContainer="false" 
     android:stretchMode="columnWidth" 
     android:verticalSpacing="10dp" 
     /> 
      ... 

     </LinearLayout> 
</ScrollView> 

项目:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView 
    android:id="@+id/horizontal_item_view_image" 
    android:layout_marginRight="10dp" 
    android:layout_width="109dp" 
    android:layout_height="109dp" /> 

</LinearLayout> 

适配器:

public class HorizontalPhotosAdapter extends RecyclerView.Adapter<HorizontalPhotosAdapter.MyViewHolder> { 

    private Context context; 
    private LayoutInflater inflater; 
    private ArrayList<Bitmap> bitmapList; 

    public class MyViewHolder extends RecyclerView.ViewHolder { 

     private ImageView riv; 

     public MyViewHolder(View view) { 
      super(view); 

      riv = (ImageView) view.findViewById(R.id.horizontal_item_view_image); 

     } 
    } 


    public HorizontalPhotosAdapter(Context context, ArrayList<Bitmap> bitmapList, String[] imageUrls) { 
     this.context = context; 
     this.bitmapList = bitmapList; 
    } 

    @Override 
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
     View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.horizontal_item_view, parent, false); 

     if (itemView.getLayoutParams().width == RecyclerView.LayoutParams.MATCH_PARENT) 
      itemView.getLayoutParams().width = RecyclerView.LayoutParams.WRAP_CONTENT; 

     return new MyViewHolder(itemView); 
    } 

    @Override 
    public void onBindViewHolder(final MyViewHolder holder, final int position) { 

     holder.riv.setImageBitmap(bitmapList.get(position)); 

    } 


    @Override 
    public int getItemCount() { 
     return bitmapList.size(); 
    } 
} 

实施片段/活动:如果

  horizontalAdapter=new HorizontalPhotosAdapter(getContext(), bitmapList); 
      horizontal_recycler_view.setAdapter(horizontalAdapter); 
      horizontalAdapter.notifyDataSetChanged(); 

      LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false); 
      horizontal_recycler_view.setLayoutManager(horizontalLayoutManagaer); 
      horizontal_recycler_view.setAdapter(horizontalAdapter); 
相关问题