【发布时间】:2015-01-16 10:30:12
【问题描述】:
我有一个带有一些布局的 listView,我已将这个问题的它简化到最大,但它仍然不能像预期的那样工作。会发生什么:
1) ListView 的第一行正常工作:它是“可抓取的”,即我可以触摸它并向上或向下移动手指,滚动它。
2) listView 中的所有其他行只能由“ikonka”和“tojkat”ImageViews 抓取
这是布局:
<?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>
适配器,为本问题的目的而简化:
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;
}
}
我认为这并不重要,但 ListView 是 FragmentStatePagerAdapter 创建的片段的一部分,它是属于 Activity 的片段的成员...
对我来说,它看起来像 Android 错误(第一行有效!),但我可能错了。有什么想法吗?
编辑:有趣的是,用新的 ImageView 填充整个布局并没有改变任何东西 - 只有“旧”的 ImageView 可以被抓取来滚动。
编辑:更有趣的是:制作 trojkat 视图宽度 match_parent,不会改变任何东西!仍然只有视图左右两侧的小区域可用于滚动。
编辑:哦,天哪!我找到了!发生的情况是位于当前片段下方的片段接收所有滚动事件!现在我将如何覆盖这种愚蠢的行为?!
编辑和解决方案:这是使用 PageTransformer 时发生的错误!在这里寻找解决方案:ListView inside ViewPager won't scroll when applying a PageTransformer
【问题讨论】:
-
在适配器构造器中,你能应用上下文并检查一次吗?
-
在什么意义上检查它?请注意,在 bindView 或 newView 中都没有使用上下文。你认为我应该每次都从 newView 中的当前上下文创建充气器吗?
-
没有。我怀疑从上下文膨胀。我认为您需要更改上下文。
-
此适配器从托管所有片段的活动中获取其上下文。
标签: android listview fragment adapter