2017-02-26 82 views
1

所以我有下面的設計思路,我想要的是所有的元素順利滾動到一起,也支持刷卡刷新。NestedScrollview和SwipeRefreshLayout下的多個視圖(滾動問題)

enter image description here

我已經測試了安卓4.4.4以下的XML和它完美的作品。卷軸快速平滑,一切都很好!然而,當我將它部署的Android 7.1.1,滾動變得很laggy大部分的時間,當你刪除,而不是放慢你的手指,它停止..

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
> 


<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/swipeContainer" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/myScrollView" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"> 


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


      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="300dp" 
       android:src="@drawable/mypicture" 
       android:scaleType="centerCrop" 
       android:id="@+id/top1pic" /> 

      <RelativeLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_marginTop="230dp" 
       android:background="@drawable/gradient_home_50"> 

       <TextView 
        android:text="Hello" 
        android:ellipsize="end" 
        android:maxLines="1" 
        android:paddingLeft="10dp" 
        android:textColor="@color/white" 
        android:textSize="27sp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/textView3" /> 

       <TextView 
        android:text="you are" 
        android:textColor="@color/white" 
        android:textSize="19sp" 
        android:paddingLeft="10dp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_below="@id/textView3" 
        android:layout_marginBottom="10dp" 
        android:id="@+id/textView5" /> 

       <ImageView 
        android:layout_marginLeft="10dp" 
        android:layout_width="30dp" 
        android:layout_height="30dp" 
        android:layout_below="@id/textView3" 
        android:layout_toEndOf="@id/textView5" 
        android:layout_marginBottom="10dp" 
        android:src="@drawable/rhome" 
        android:scaleType="centerCrop" 
        android:id="@+id/number1pic" /> 

      </RelativeLayout> 


      <Space 
       android:layout_width="1dp" 
       android:layout_height="10dp" 
       android:layout_below="@id/top1pic" 
       android:id="@+id/uselessSpace"/> 

      <TextView 
       android:text="Sup" 
       android:paddingLeft="10dp" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/uselessSpace" 
       android:layout_marginTop="5dp" 
       android:textStyle="bold" 
       android:id="@+id/textView1" /> 

      <TextView 
       android:text="mpla mpla" 
       android:paddingLeft="10dp" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/textView1" 
       android:id="@+id/textView10" /> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/horizontalRecycler" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/numberOfPeopleHere" 
       android:minHeight="200dp" 
       android:maxHeight="200dp" 
       android:paddingTop="10dp" /> 

      <TextView 
       android:text="mpla mpla" 
       android:textStyle="bold" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_below="@id/horizontalRecycler" 
       android:paddingBottom="10dp" 
       android:id="@+id/textView4" /> 


      <android.support.v7.widget.RecyclerView 
       android:id="@+id/homelist" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_below="@id/textView4" 
       android:layout_alignParentBottom="true" 
       android:paddingBottom="48dp" 
       android:maxHeight="200dp" 
       android:clipToPadding="false" 
       /> 

      <Space 
       android:layout_width="1dp" 
       android:layout_height="10dp" 
       android:layout_above="@id/homelist" 
       android:id="@+id/uselessSpace2" 
       android:visibility="gone" 
       /> 

     </RelativeLayout> 
    </android.support.v4.widget.NestedScrollView> 

</android.support.v4.widget.SwipeRefreshLayout> 

<LinearLayout 
    android:id="@+id/progressbarlayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 

    android:gravity="center_horizontal" 
    android:orientation="horizontal" 
    android:weightSum="1"> 

    <ProgressBar 
     style="@android:style/Widget.Holo.Light.ProgressBar.Small" 
     android:layout_width="20dp" 
     android:layout_height="20dp" 
     android:layout_gravity="center" 
     android:layout_marginEnd="5dp" 
     android:layout_marginRight="5dp"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="All good?" 
     android:textColor="@android:color/black" 
     android:textSize="15sp" 
     android:gravity="center" 
     android:textStyle="bold" 
     /> 
    <!--android:layout_weight="138.70" 
    (was in textview above)--> 
</LinearLayout> 


<TextView 
    android:id="@+id/toolbar_title" 
    style="@style/Base.TextAppearance.Widget.AppCompat.Toolbar.Title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:layout_centerHorizontal="true" 
    android:paddingTop="10dp" 
    android:textColor="@android:color/white" 
    android:shadowColor="@android:color/black" 
    android:shadowRadius="3" 
    android:textSize="20sp" 
    android:visibility="gone"/> 

而且我已經添加了以下行主類的片段:

// for the vertical RecyclerView 
recyclerView = (RecyclerView) v.findViewById(R.id.homelist); 

recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false) { 
      @Override 
      public boolean canScrollVertically() { 
       return false; 
      } 
}); 

recyclerView.setNestedScrollingEnabled(false); 

// for the horizontal RecyclerView  
RHRNRecycler = (RecyclerView) v.findViewById(R.id.horizontalRecycler); 
RHRNRecycler.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false) { 
      @Override 
      public boolean canScrollVertically() { 
       return false; 
      } 
}); 

等具有一些與NestedScrollView所有這些版本中被改變,這意味着我必須要徹底改變我實現這個設計的呢?有沒有更好的方法來做到這一點(標準方面)?

回答

0

對於那些仍在看這篇文章的人來說,我所做的就是將所有內容都放在一個回收站中(第一個單元有「imageview和一些相關元素」,第二個單元有水平回收視圖,第三個有數據垂直的一個)。

但是,這並沒有解決順利滾動問題。我發現,在垂直方向上,我使用了一些太大的圖像(可繪製),所以它們在運行時必須縮小比例,從而導致速度放慢。

我的提示是,只要你可以使用緩存圖像加載庫(Glide太棒了!),例如從互聯網下載時。另外,當你想要從drawable中加載圖片(在xml中使用'android:src'),一定要利用android提供的不同的可繪製文件夾。這真的可以幫助提高性能!

0

您是否嘗試添加下一行?

recyclerView.setNestedScrollingEnabled(false);