我有一个正常打开的抽屉,但是滚动非常慢,我不知道为什么知道它上面的图像不是HD图像,并且有4种尺寸,我我已经用Java完成了各种示例,这很好,我想知道问题是否在于我在适配器中使用Kotlin。 我将不胜感激。
活动的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient_background"
android:orientation="vertical">
<include
android:id="@+id/top"
layout="@layout/top_bar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" />
<TextView
android:layout_below="@+id/top"
android:id="@+id/tvTradesTicker"
android:layout_width="match_parent"
android:layout_height="@dimen/trades_ticker_height"
android:background="@color/colorPrimaryLight"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:focusable="true"
android:freezesText="true"
android:marqueeRepeatLimit="marquee_forever"
android:padding="@dimen/small_margin"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="@color/darkGray"
android:textSize="@dimen/font"
android:visibility="visible" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvGrid"
android:layout_below="@+id/tvTradesTicker"
android:layout_above="@+id/llFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
layout="@layout/footer"
android:id="@+id/llFooter"
android:layout_width="match_parent"
android:layout_height="@dimen/footer_height"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/white"
android:fitsSystemWindows="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:paddingTop="@dimen/big_margin_padding"
android:orientation="vertical">
<include
layout="@layout/item_drawer_header"
android:id="@+id/header"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="@dimen/drawer_header_height" />
<ListView
android:id="@+id/lvItems"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/white"
android:divider="@android:color/transparent"
android:paddingTop="@dimen/small_margin" />
</LinearLayout>
</android.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)
}
我应该更改什么,活动布局或适配器,或者我真的不知道。
编辑
我将布局中的选取框文本视图的可见性设置为不可见,并且一切正常,有人知道为什么吗?因为我不想将文本视图替换为水平的回收器视图
答案 0 :(得分:0)
已解决。
完全改变了方法,我停止了选取框并将交叉淡入淡出动画应用于文本视图,并带有一个处理程序,该处理程序在每次迭代时都会更改在文本视图中设置的对象,现在它看起来很完美,而且更具弹性。