StickyGridHeader自定义标题显示错误的大小

时间:2014-06-12 06:02:03

标签: android android-gridview

我使用StickyGridHeader库和自定义标题视图,如下图所示。问题是这个标题仅在顶部粘滞时起作用。在正常状态下,它显示宽度不正确,我认为它是由StickyGridHeadersGridView

测量标题大小引起的

enter image description here

这是我的标题布局:

<?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:paddingBottom="10dp"
android:paddingTop="10dp" >

<TextView
    android:id="@+id/tvHeaderName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@+id/tvHeaderDate"
    android:minWidth="250dp"
    android:paddingLeft="10dp"
    android:text="aaa"
    android:textColor="@color/white"/>

<TextView
    android:id="@+id/tvHeaderDate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:paddingRight="10dp"
    android:text="aaa"
    android:textColor="@color/white" />

  <!--gray line-->
<View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:layout_below="@+id/tvHeaderDate"
    android:layout_marginTop="10dp"
    android:background="@color/gray_line" />

 </RelativeLayout>

我的适配器:

public class GalleryAdapter extends BaseAdapter implements StickyGridHeadersBaseAdapter {

     // initialize image item ...


    @Override
    public int getCountForHeader(int position) {
        return getHeaderItem(position).getImages().size();
    }

    public GalleryItem getHeaderItem(int position) {
        return parents.get(position);
    }

    @Override
    public View getHeaderView(int position, View view, ViewGroup parent) {
        HeaderViewHolder viewHolder;
        if (view == null) {
            view = mInflater.inflate(R.layout.item_header_gallery, parent, false);
            viewHolder = new HeaderViewHolder();
            viewHolder.tvHeaderName = (TextView) view.findViewById(R.id.tvHeaderName);
            viewHolder.tvHeaderDate = (TextView) view.findViewById(R.id.tvHeaderDate);
            view.setTag(viewHolder);
        } else {
            viewHolder = (HeaderViewHolder) view.getTag();
        }

        viewHolder.tvHeaderName.setText(getHeaderItem(position).getGroupName());
        viewHolder.tvHeaderDate.setText(getHeaderItem(position).getTime());
        return view;
    }

    @Override
    public int getNumHeaders() {
        return parents.size();
    }

    private static class HeaderViewHolder {
        public TextView tvHeaderName;
        public TextView tvHeaderDate;
    }

有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

我认为你应该尝试我在另一个question中说的话。 基本上,你必须用另一个jar stickygridheaders.jar替换你的stickygridheaders.jar或gradle中的依赖项{{3}}