java抽屉正在缓慢滚动
我有一个抽屉,它可以正常打开,但是里面的滚动速度非常慢,我不知道为什么知道它上面的图像不是高清图像,并且有4种尺寸,我用Java做了各种各样的例子,很好,我想知道问题是我在适配器中使用了Kotlin。 我将感谢任何帮助
活动的布局:
<?xml version="1.0" encoding="utf-8"?>
<安卓.support.v4.widget.DrawerLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:id="@+id/drawer_layout"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="@安卓:color/white"
安卓:fitsSystemWindows="true">
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="@drawable/gradient_background"
安卓:orientation="vertical">
<include
安卓:id="@+id/top"
layout="@layout/top_bar"
安卓:layout_width="match_parent"
安卓:layout_height="?安卓:attr/actionBarSize" />
<TextView
安卓:layout_below="@+id/top"
安卓:id="@+id/tvTradesTicker"
安卓:layout_width="match_parent"
安卓:layout_height="@dimen/trades_ticker_height"
安卓:background="@color/colorPrimaryLight"
安卓:ellipsize="marquee"
安卓:fadingEdge="horizontal"
安卓:focusable="true"
安卓:freezesText="true"
安卓:marqueeRepeatLimit="marquee_forever"
安卓:padding="@dimen/small_margin"
安卓:scrollHorizontally="true"
安卓:singleLine="true"
安卓:textColor="@color/darkGray"
安卓:textSize="@dimen/font"
安卓:visibility="visible" />
<安卓.support.v7.widget.RecyclerView
安卓:id="@+id/rvGrid"
安卓:layout_below="@+id/tvTradesTicker"
安卓:layout_above="@+id/llFooter"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content" />
<include
layout="@layout/footer"
安卓:id="@+id/llFooter"
安卓:layout_width="match_parent"
安卓:layout_height="@dimen/footer_height"
安卓:layout_alignParentBottom="true"/>
</RelativeLayout>
<安卓.support.design.widget.NavigationView
安卓:id="@+id/nav_view"
安卓:layout_width="wrap_content"
安卓:layout_height="match_parent"
安卓:layout_gravity="start"
安卓:background="@color/white"
安卓:fitsSystemWindows="true" >
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:background="@color/white"
安卓:paddingTop="@dimen/big_margin_padding"
安卓:orientation="vertical">
<include
layout="@layout/item_drawer_header"
安卓:id="@+id/header"
安卓:background="@color/white"
安卓:layout_width="match_parent"
安卓:layout_height="@dimen/drawer_header_height" />
<ListView
安卓:id="@+id/lvItems"
安卓:layout_width="match_parent"
安卓:layout_height="0dp"
安卓:layout_weight="1"
安卓:background="@color/white"
安卓:divider="@安卓:color/transparent"
安卓:paddingTop="@dimen/small_margin" />
</LinearLayout>
</安卓.support.design.widget.NavigationView>
抽屉的适配器:
class DrawerListAdapter : BaseAdapter {
private var drawerItems: MutableList<DrawerItem> = mutableListOf()
private var context: Context? = null
constructor(context: Context, notesList: MutableList<DrawerItem>) : super() {
this.drawerItems = notesList
this.context = context
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
val view: View?
val vh: ViewHolder
val inflater = LayoutInflater.from(context)
val type = getItemViewType(position)
if (convertView == null) {
view = if (type == 0){
inflater.inflate(R.layout.item_drawer_section, parent, false)
}else{
inflater.inflate(R.layout.item_drawer_child, parent, false)
}
vh = ViewHolder(view)
view.tag = vh
} else {
view = convertView
vh = view.tag as ViewHolder
}
val drawerItem = drawerItems[position]
vh.name.text = drawerItem.name
if (type == 0){
vh.rel.setBackgroundColor(ContextCompat.getColor(context!!, R.color.blue))
vh.name.setBackgroundColor(ContextCompat.getColor(context!!, R.color.colorAccent))
vh.name.setTextColor(ContextCompat.getColor(context!!, R.color.white))
}else if (type == 1){
vh.rel.setBackgroundColor(ContextCompat.getColor(context!!, R.color.white))
vh.name.setBackgroundColor(ContextCompat.getColor(context!!, R.color.white))
vh.name.setTextColor(ContextCompat.getColor(context!!, R.color.colorPrimary))
vh.separator.visibility = View.VISIBLE
}else{
vh.rel.setBackgroundColor(ContextCompat.getColor(context!!, R.color.white))
vh.name.setBackgroundColor(ContextCompat.getColor(context!!, R.color.white))
vh.name.setTextColor(ContextCompat.getColor(context!!, R.color.colorPrimary))
vh.separator.visibility = View.GONE
}
Actions.overrideFonts(context!!, vh.rel)
return view
}
override fun getItem(position: Int): DrawerItem {
return drawerItems[position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getCount(): Int {
return drawerItems.size
}
override fun getItemViewType(position: Int): Int {
if (drawerItems[position].isHeader)
return 0
else if (!drawerItems[position].isLast)
return 1
else
return 2
}
override fun getViewTypeCount(): Int {
return 3
}
}
private class ViewHolder(view: View) {
val rel: RelativeLayout = view.findViewById(R.id.rel) as RelativeLayout
val name: TextView = view.findViewById(R.id.name) as TextView
val separator = view.findViewById<View>(R.id.separator)
}
我应该改变什么,活动布局,适配器或者我真的不知道的东西
编辑
我将布局中的字幕文本视图的可见性设置为“消失”,一切正常,有人知道为什么吗?因为我不想用水平回收器视图替换此文本视图
# 1 楼答案
解决了
完全改变了方法,我停止了选框,并将交叉淡入淡出动画应用到文本视图,使用一个处理程序在每次迭代时更改文本视图中设置的对象,现在它看起来非常完美,更加优雅