Android ListView在相同类型的设备上的行为不同 [英] Android listview behave differently on same kind of device

查看:148
本文介绍了Android ListView在相同类型的设备上的行为不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与一个让我发疯的问题作斗争: 我有一个非常简单的ListView,它可以在一台设备上平滑滚动,而在另一台几乎100%相同的设备上却很笨拙.

此处,您可以找到滚动动画的视频和此处,您可以找到(几乎)平滑视频滚动.

缓慢滚动发生在具有规格的设备上,则平滑滚动会在具有规格的设备上发生

这是我使用的最基本的代码(显然使用ViewHolder模式),这怎么可能?请有人帮我!!!

public DealerAdapter(Context context, int skinLayoutResourceId, ArrayList<Dealer> items) {
        super(context, skinLayoutResourceId, items);
        _items = items;
        mContext = context;
        layout = skinLayoutResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DealerViewHolder holder = null;
        // reuse views
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(layout, null);
            // configure view holder
            holder = new DealerViewHolder();
            holder.lblName = (TextView) convertView.findViewById(R.skinDealer.lblNameSurname);
            holder.lblSapCode = (TextView) convertView.findViewById(R.skinDealer.lblSapCode);
            holder.lblAddress = (TextView) convertView.findViewById(R.skinDealer.lblAddress);
            convertView.setTag(holder);
        } else
            holder = (DealerViewHolder) convertView.getTag();
        try {
            holder.lblName.setText(_items.get(position).getName());
            holder.lblCode.setText(_items.get(position).getCode());
            holder.lblAddress.setText(_items.get(position).getAddress());
        } catch (Exception e) {
            // TODO: handle exception
        }
        return convertView;
    }

    static class DealerViewHolder {
        TextView lblName;
        TextView lblAddress;
        TextView lblCode;
    }

我在另一台三星设备Galaxy galaxy note 10.1上测试了相同的代码,其操作系统版本与平滑滚动且具有更强大的硬件的OS版本相同,结果令人惊讶! 此处是行为,解决方案

经过数周的调查,其原因令人难以置信:问题是由包含列表视图的布局根目录上的背景图像太大(几乎是2MB).尽管我知道使用大图像作为背景不是一个好习惯,但我真的不明白为什么在高性能设备上会引起问题,而在性能较差的设备上却一切运行正常!

顺便说一句,我希望这可以帮助遇到我同样问题的任何人

I'm fighting with a problem that is driving me crazy: I have a very simple ListView which scroll smoothly on a device and very luggy on another device that is almost 100% the same.

here you can find a video of the luggy scroll and here you can find a video of the (almost) smooth scrolling.

the slow scroll happens on a device with this specs, the smooth scroll happens on a device with this specs

here is the very basic code I used (obviously using ViewHolder pattern), how the hell can it be possible?? Please somebody help me!!!

public DealerAdapter(Context context, int skinLayoutResourceId, ArrayList<Dealer> items) {
        super(context, skinLayoutResourceId, items);
        _items = items;
        mContext = context;
        layout = skinLayoutResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DealerViewHolder holder = null;
        // reuse views
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(layout, null);
            // configure view holder
            holder = new DealerViewHolder();
            holder.lblName = (TextView) convertView.findViewById(R.skinDealer.lblNameSurname);
            holder.lblSapCode = (TextView) convertView.findViewById(R.skinDealer.lblSapCode);
            holder.lblAddress = (TextView) convertView.findViewById(R.skinDealer.lblAddress);
            convertView.setTag(holder);
        } else
            holder = (DealerViewHolder) convertView.getTag();
        try {
            holder.lblName.setText(_items.get(position).getName());
            holder.lblCode.setText(_items.get(position).getCode());
            holder.lblAddress.setText(_items.get(position).getAddress());
        } catch (Exception e) {
            // TODO: handle exception
        }
        return convertView;
    }

    static class DealerViewHolder {
        TextView lblName;
        TextView lblAddress;
        TextView lblCode;
    }

EDIT:

I tested the same code on another samsung device, galaxy note 10.1, with the same OS version as the one having a smooth scrolling and with more powerfull hardware, the result is surprending!! Here is the behavior, here are the device's specs.

Some times android is a real giant question mark!!!!

EDIT 2:

Here is logcat while executing a scroll on the device with android 4.2.2

01-27 10:34:59.994: V/AlarmManager(2371): waitForAlarm result :8
01-27 10:35:00.004: D/KeyguardClockWidgetService(4910): onReceive action=android.intent.action.TIME_TICK
01-27 10:35:00.004: V/AlarmManager(2371): ClockReceiver onReceive() ACTION_TIME_TICK
01-27 10:35:00.034: D/IconMerger(2561): overflowShown = false
01-27 10:35:00.034: D/IconMerger(2561): moreRequired = false
01-27 10:35:00.094: I/WAKELOCK_RELEASE(2371): TIMESTAMP=3927849415108, TAG=AlarmManager, TYPE=PARTIAL_WAKE_LOCK             , COUNT=0, PID=2371, UID=1000
01-27 10:35:00.474: I/InputReader(2371): Touch event's action is 0x0 (deviceType=0) [pCnt=1, s=0.146 ] when=3598409874000
01-27 10:35:00.474: I/InputDispatcher(2371): Delivering touch to: action: 0x0
01-27 10:35:00.494: I/ThermalZone(2371): TEMP 41000 newMaxSensorState 0
01-27 10:35:00.504: I/CustomFrequencyManager(4461): newFrequencyRequest  - mFrequency = 800000, mTimeoutMs = -1, mPkgName = LIST_SCROLL_BOOSTER@3
01-27 10:35:00.504: I/CustomFrequencyManager(4461): Boost Request from package = LIST_SCROLL_BOOSTER@3 frequency : 800000type = 6
01-27 10:35:00.504: I/CustomFrequencyManager(4461): !! pkgName = LIST_SCROLL_BOOSTER@3
01-27 10:35:00.504: I/CustomFrequencyManager(4461): Request from package name pkgName = LIST_SCROLL_BOOSTER@3
01-27 10:35:00.504: I/CustomFrequencyManager(4461): mContext is Not Null  mContext.pkgName = com.reply.fasttrack
01-27 10:35:00.504: I/CustomFrequencyManager(4461): mToken is Null....Creating New Binder!
01-27 10:35:00.504: I/CustomFrequencyManager(4461): CPUDVFSControlRequest : doFrequencyRequest::  = 800000 Timeout : -1
01-27 10:35:00.504: I/power(2371): *** acquire_dvfs_lock : lockType : 1  freq : 800000 
01-27 10:35:00.504: D/CustomFrequencyManagerService(2371): acquireDVFSLockLocked : type : DVFS_MIN_LIMIT  frequency : 800000  uid : 10169  pid : 4461  pkgName : LIST_SCROLL_BOOSTER@3
01-27 10:35:00.614: I/InputReader(2371): Touch event's action is 0x1 (deviceType=0) [pCnt=1, s=] when=3598555846000
01-27 10:35:00.614: I/InputDispatcher(2371): Delivering touch to: action: 0x1
01-27 10:35:01.984: I/Monitor(2371): SIOP:: Current AP = 365, CP = 0
01-27 10:35:03.354: D/BatteryService(2371): update start
01-27 10:35:03.354: D/BatteryService(2371): level:21, scale:100, status:3, health:2, present:true, voltage: 3614, temperature: 319, technology: Li-ion, AC powered:false, USB powered:true, Wireless powered:false, icon:17303346, invalid charger:0, online:4, charge type:1, current avg:-368
01-27 10:35:03.354: D/BatteryService(2371): Sending ACTION_BATTERY_CHANGED.
01-27 10:35:03.364: D/STATUSBAR-BatteryController(2561): onReceive() - ACTION_BATTERY_CHANGED
01-27 10:35:03.364: D/STATUSBAR-BatteryController(2561): onReceive() - BATTERY_STATUS_DISCHARGING: tw_stat_sys_battery_usb_not_charge
01-27 10:35:03.364: D/STATUSBAR-PhoneStatusBar(2561):  mBrightnessEnablebySettings = true mBrightnessEnablebyBattery = true mBrightnessEnablebyDisableFlag = true
01-27 10:35:03.514: I/power(2371): *** release_dvfs_lock : lockType : 1 
01-27 10:35:03.514: D/CustomFrequencyManagerService(2371): releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT  frequency : 800000  uid : 10169  pid : 4461  tag : LIST_SCROLL_BOOSTER@3

解决方案

After weeks of investigating, the reason was unbelievable: the problem was caused from a background image on the root of the layout containing the listview that was too big (almost 2MB). Although I know that using big images as background is not a good practice, I really do not understand why on an high performance device this was causing problem and on a less-performant device everything was running perfectly!

By the way I hope this will help anyone having my same problem

这篇关于Android ListView在相同类型的设备上的行为不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆