2

我有一个我正在尝试设置的布局,它由三种不同的布局合并为一个。我有两个 RelativeLayouts 作为前两项,一个列表适配器作为第三项。使用 MergeAdapter 的原因是因为我希望整个页面滚动,但我希望整个布局中的第二个总项(第二个 RelativeLayout)粘在顶部。所以我正在尝试使用StickyListHeaders 库来完成它。

它似乎还没有被广泛使用,尽管它的想法很棒。无论如何,我必须在我的列表适配器中覆盖两种方法,在这种情况下是 MergeAdapter。我不断收到 NullPointerException,但它并没有告诉我它在我的代码中发生的位置。因此,如果有人有使用该库的经验,更具体地说是使用 MergeAdapter 的库,你能告诉我我做错了什么吗?这是我的 MergeAdapter 的代码。

private class ProfileMergeAdapter extends MergeAdapter implements StickyListHeadersAdapter{

    @Override
    public View getHeaderView(int position, View convertView, ViewGroup parent) {

        LayoutInflater nameInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = (RelativeLayout) nameInflater.inflate(R.layout.name_line, null);
        profilePhotoBottom = (ImageView) convertView.findViewById(R.id.profile_pic_bottom);
        TextView userName = (TextView) convertView.findViewById(R.id.userName);
        userName.setText(Utility.userName);
        return convertView;
    }

    @Override
    public long getHeaderId(int position) {
        return 1;
    }

}

这是logcat:

01-13 20:39:21.237: W/dalvikvm(4917): threadid=1: thread exiting with uncaught exception (group=0x40de5930)
01-13 20:39:21.245: E/AndroidRuntime(4917): FATAL EXCEPTION: main
01-13 20:39:21.245: E/AndroidRuntime(4917): java.lang.NullPointerException
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:523)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.view.View.measure(View.java:15513)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at com.emilsjolander.components.stickylistheaders.StickyListHeadersListView.measureHeader(StickyListHeadersListView.java:242)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at com.emilsjolander.components.stickylistheaders.StickyListHeadersListView.scrollChanged(StickyListHeadersListView.java:284)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at com.emilsjolander.components.stickylistheaders.StickyListHeadersListView.onScroll(StickyListHeadersListView.java:269)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.widget.AbsListView.invokeOnItemScrollListener(AbsListView.java:1340)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.widget.ListView.layoutChildren(ListView.java:1753)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.widget.AbsListView.onLayout(AbsListView.java:1994)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.view.View.layout(View.java:14003)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.view.View.layout(View.java:14003)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.view.View.layout(View.java:14003)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.view.View.layout(View.java:14003)
01-13 20:39:21.245: E/AndroidRuntime(4917):     at android.view.ViewGroup.layout(ViewGroup.java:4375)
4

1 回答 1

0

谢谢马克的回复。我想通了,有点。我想我的 xml 中的 layout_width 和 layout_height 对于其中一个列表项有问题,并且更改它们不起作用。所以我在代码中使用 LayoutParams 更改了项目的高度和宽度。

于 2013-01-15T01:23:34.023 回答