简体   繁体   English

ListView滚动奇怪的行为

[英]ListView scrolling strange behaviour

I have a listView with some layout, I've simplified it for this question to the maximum, but it still doesn't work as epected. 我有一个带有某些布局的listView,我已将此问题简化到最大程度,但仍然无法正常使用。 What happens it that: 发生了什么事:

1) first row of the ListView works properly: it is "grabbable", ie I can touch it and moving finger up or down, scroll it. 1)ListView的第一行工作正常:它是“可抓取的”,即,我可以触摸它并向上或向下移动手指来滚动它。

2) all other rows in the listView are grabbable only by "ikonka" and "tojkat" ImageViews 2)listView中的所有其他行只能由“ ikonka”和“ tojkat” ImageViews抓取

Here's the layout: 这是布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:gravity="bottom" >

    <ImageView
        android:focusable="false"
        android:id="@+id/ikonka"
        android:layout_width="@dimen/listview_album_art"
        android:layout_height="@dimen/listview_album_art"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:paddingBottom="@dimen/audio_player_icon_padding"
        android:paddingTop="@dimen/audio_player_icon_padding"
        android:scaleType="centerCrop" />

    <ImageView
        android:focusable="false"
        android:id="@+id/akcja"
        android:layout_width="@dimen/listview_album_art"
        android:layout_height="@dimen/listview_album_art"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginBottom="@dimen/audio_player_icon_padding"
        android:layout_marginTop="@dimen/audio_player_icon_padding"
        android:scaleType="centerCrop" />

    <ImageView
        android:focusable="false"
        android:id="@+id/trojkat"
        android:layout_width="50dip"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@null"
        android:scaleType="center"
        android:src="@drawable/ic_action_overflow" />

</RelativeLayout>

The adapter, simplified for the purpose of this question: 适配器,针对此问题而简化:

 public class AdapterTrackowDlaZapytan extends CursorAdapter {
LayoutInflater inflater = null;

public AdapterTrackowDlaZapytan(FragmentActivity c, Cursor cu, int flags) {
    super(c, cu, flags);

    inflater = (LayoutInflater) c
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    // nothing really interesting here, besides ViewHolder, but even without it it works as described
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup vg) {
    ViewHolder holder;

    View v = inflater.inflate(R.layout.test_directory_row, vg, false);
    return v;
}

  }

I don't think it matters, but the ListView is part of a fragment that is created by FragmentStatePagerAdapter that is a member of a fragment that belongs to an Activity... 我不认为这很重要,但是ListView是FragmentStatePagerAdapter创建的片段的一部分,FragmentStatePagerAdapter是属于Activity的片段的成员...

For me it looks like Android bug (the first row works!), but I might be wrong. 对我来说,它看起来像是Android错误(第一行有效!),但我可能错了。 Any thoughts? 有什么想法吗?

EDIT: interestingly, filling the whole layout with new ImageView didn't change anything - only "old" ImageViews can be grabbed to scroll. 编辑:有趣的是,用新的ImageView填充整个布局没有任何改变-只能抓取“旧” ImageViews进行滚动。

EDIT: even more interesting: making trojkat view width match_parent, doesn't change anything! 编辑:更有趣:使trojkat视图宽度match_parent,什么都不会改变! Still only small areas on the left and right of the view can be used to scroll. 仍然只能使用视图左侧和右侧的一小部分区域进行滚动。

EDIT: oh, my! 编辑:哦,我的! I've found it! 我找到了! What happens is that a fragment that is laying BELOW current fragment receives all scroll events! 发生的是位于当前片段下方的片段接收所有滚动事件! Now how would I override that stupid behaviour?! 现在,我将如何替代这种愚蠢的行为?

EDIT AND SOLUTION: This is a bug that happens when using PageTransformer! 编辑和解决方案:这是使用PageTransformer时发生的错误! Look for solution here: ListView inside ViewPager won't scroll when applying a PageTransformer 在此处查找解决方案: 应用PageTransformer时,ViewPager中的ListView不会滚动

As I suspected, the bug is Android bug and it happens due to PageTransformer, see here: 正如我所怀疑的那样,该错误是Android错误,它是由于PageTransformer而发生的,请参见此处:

ListView inside ViewPager won't scroll when applying a PageTransformer 应用PageTransformer时,ViewPager中的ListView不会滚动

It would be good to leave this question for anyone in the future looking for the answer, as this bug might manifest itself in very strange ways, and it is not so easy to guess it is caused by PageTransformer! 将来最好将这个问题留给任何人寻找答案,因为此错误可能以非常奇怪的方式表现出来,并且很难想象它是由PageTransformer引起的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM