抽屉慢慢滚动

问题描述 投票:0回答:1

我有这个抽屉正常打开,但滚动速度非常慢,我不知道为什么知道它上面的图像不是高清图像,并提供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)

   }

我应该改变什么,活动布局,或适配器或我真的不知道。

编辑

我将布局中的选取框文本视图的可见性设置为已消失,一切正常,有人知道为什么吗?因为我不想用水平回收者视图替换此文本视图

java android kotlin adapter
1个回答
0
投票

解决了。

完全改变了方法,我停止了选取框并将交叉淡入淡出动画应用到文本视图中,使用处理程序在每次迭代时更改在文本视图中设置的对象,现在它看起来很完美而且更加方便elegnat

© www.soinside.com 2019 - 2024. All rights reserved.