【发布时间】:2014-07-01 01:20:51
【问题描述】:
在一个片段中,我有一个具有自定义 ParseQueryAdapter<T> 的 ListView。这个问题可能与 Parse 没有任何关系,尽管我不确定。
在测试我的应用程序时,我注意到一些非常奇怪的事情。当我向下滚动 ListView 时,所有可见的 ListView 项目都将绘制在下一个 ListView 项目的顶部,如下面的第二张图片所示。
列表正确初始化如下:
如您所见,在我的列表项布局中,我有一个 ImageView(具体来说是ParseImageView)和一个 TextView。 TextView 现在显示一些注释(不要介意 ID user_name_text_view),ImageView 显示占位符空白个人资料图片。
当我向下滚动时,列表看起来像:
这是我的列表视图布局,名为fragment_post_view_list_view:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/post_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
这是我的列表项布局,名为list_item_post_view:
<?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">
<com.parse.ParseImageView
android:id="@+id/icon"
android:layout_width="75dp"
android:layout_height="75dp"
android:layout_alignParentLeft="true"
android:background="@drawable/com_facebook_profile_picture_blank_square" />
<TextView
android:id="@+id/user_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/icon"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/link_blue" />
</RelativeLayout>
这是我的适配器,名为PostViewListViewAdapter:
public class PostViewListViewAdapter extends ParseQueryAdapter<Post> {
// call superclass with a query to populate list view
public PostViewListViewAdapter(Context context, final String[] postsObjectIds) {
super(context, new ParseQueryAdapter.QueryFactory<Post>(){
public ParseQuery<Post> create() {
ParseQuery<Post> query = Post.getQuery();
query.whereContainedIn("objectId", Arrays.asList(postsObjectIds));
return query;
}
});
}
// this is similar to getView method in an adapter
@Override
public View getItemView(Post post, View v, ViewGroup parent) {
if(v == null) {
v = View.inflate(getContext(), R.layout.list_item_post_view, null);
}
super.getItemView(post, v, parent);
TextView usernameTextView = (TextView) v.findViewById(R.id.user_name_text_view);
usernameTextView.setText(post.getNotes()); // some string
return v;
}
}
我该如何解决这个问题?
这是 XML 或 Java 的问题吗?
我正在学习 Parse 和 example from the Parse docs 的两个教程:
我在这里设置了适配器和ListView:
View rootView = inflater.inflate(R.layout.fragment_post_view_list_view, container, false);
mPostsObjectIds = SOME_STRING[];
PostViewListViewAdapter adapter = new PostViewListViewAdapter(getActivity(), mPostsObjectIds);
ListView listView = (ListView) rootView.findViewById(R.id.post_list_view);
listView.setAdapter(adapter);
我已经尝试在列表项布局中删除 ParseImageView,但当我滚动时,我的 TextViews 仍然相互重叠。
编辑:
我忘了提到列表项在方向更改后显示在彼此之上。
我在 Galaxy S5(Android 版本 4.4.2 和 Parse 1.4.1)上对此进行了测试。
在我的活动中,我在此处显示片段(称为PostViewListViewFragment):
getSupportFragmentManager().beginTransaction().add(android.R.id.content, new PostViewListViewFragment()).commit();
【问题讨论】:
标签: android android-layout android-listview parse-platform