求助:CollapsingToolbarLayout如何性能优化

CarsonWoo 2018-05-25 01:49:43
最近在试着开发一个app 其中在一个Fragment中运用到了CollaspingToolbarLayout这个布局以想实现一个下滑时 用户头像自动缩进的功能。但是 每次切换fragment时 每当滑动(即用户头像出现)时就显得异常地卡顿 而当头像滑出屏幕时 (下面嵌套了一个tablayout+viewpager+recyclerview)滑动recyclerview时则不会卡顿 反而很流畅 想问问大神们是这个布局放在fragment中会特别卡顿吗 我应该怎么去改善性能呢?

附上我布局的xml
<android.support.design.widget.CoordinatorLayout
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"
tools:context="com.example.carson.graphsgo.Views.User.UserFragment">

<!--will be so slow switching must to give it up.-->
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_user"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="180dp"
app:contentScrim="@color/colorSub"
app:layout_scrollFlags="scroll">

<RelativeLayout
app:layout_collapseMode="none"
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/civ_user_portrait"
android:layout_marginTop="30dp"
android:layout_centerHorizontal="true"
android:src="@drawable/bg_user_banner"
android:layout_width="95dp"
android:layout_height="95dp" />

<TextView
android:id="@+id/tv_name_user_fragment"
android:textSize="18.5sp"
android:textColor="@android:color/white"
android:layout_marginTop="140dp"
android:layout_centerHorizontal="true"
android:hint="@string/word_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</RelativeLayout>

</android.support.design.widget.CollapsingToolbarLayout>



</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
android:id="@+id/nest_sv_user"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">

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

<android.support.design.widget.TabLayout
android:id="@+id/tab_layout_fragment_user"
app:tabGravity="fill"
app:tabSelectedTextColor="@color/colorSub"
app:tabIndicatorColor="@color/colorSub"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.design.widget.TabItem
android:text="活动"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<android.support.design.widget.TabItem
android:text="作品"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</android.support.design.widget.TabLayout>

<android.support.v4.view.ViewPager
android:id="@+id/container_fragment_user"
android:layout_marginTop="2dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>

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

</android.support.design.widget.CoordinatorLayout>
...全文
328 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
CarsonWoo 2018-05-25
  • 打赏
  • 举报
回复
我找到了为什么了。。。原来是图片太大了。。。
CarsonWoo 2018-05-25
  • 打赏
  • 举报
回复
要注意的是我这个布局是放在Fragment的布局文件中的

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧