lucasr / twoway-view

[DEPRECATED] RecyclerView made simple
5.23k stars 1.02k forks source link

Help with spannable grid, xml attributes not being respected #211

Open Sserra90 opened 9 years ago

Sserra90 commented 9 years ago

Hi

I'm using the twoway view for the first and i'm struggling to specify the layout attributes for the views. I have tow kinds of views, header and the episode.

This is the xml of both: Show:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="@dimen/margin_16dp"
android:layout_width="248dp"
android:layout_height="160dp"
android:background="@color/black">

 //More views...

</RelativeLayout>

Header:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="54dp"
android:background="@color/red_800">
//More views

I set the height to be 54dp in the header and 160dp for the show but what i'm getting is this, it's always the same (wrong) height, the red bar is the header.

http://postimg.org/image/xx1dk45n9/

Code:

 public static class ViewHolder extends RecyclerView.ViewHolder{

    public TextView title,date,rate,episode;
    public ImageView image;

    public ViewHolder(View view) {
        super(view);
        image = (ImageView)view.findViewById(R.id.image);
        title = (TextView)view.findViewById(R.id.title);
        date = (TextView)view.findViewById(R.id.date);
        rate = (TextView)view.findViewById(R.id.rate);
        episode = (TextView)view.findViewById(R.id.episode);
    }

}

    public static class ViewHolderHeader extends RecyclerView.ViewHolder{

    public TextView date,children;

    public ViewHolderHeader(View view) {
        super(view);
        date = (TextView)view.findViewById(R.id.date);
        children = (TextView)view.findViewById(R.id.children);
    }

}

public CalendarAdapter(Context context) {
    mContext = context;
    readDateFormat(context);
    simpleDateFormat = new SimpleDateFormat(datePattern, Locale.US);
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final View view;
    if (viewType == CalendarGridItem.TYPE.SHOW.ordinal()){
        view = LayoutInflater.from(mContext).inflate(R.layout.calendar_grid_tile, parent, false);
        return new ViewHolder(view);
    }
    else {
        view = LayoutInflater.from(mContext).inflate(R.layout.calendar_grid_header, parent, false);
        return new ViewHolderHeader(view);
    }
}

  @Override
 public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    final View view = holder.itemView;
    final CalendarGridItem item = mShows.get(position);
    final SpannableGridLayoutManager.LayoutParams lp =
            (SpannableGridLayoutManager.LayoutParams) view.getLayoutParams();

    if (getItemViewType(position) == CalendarGridItem.TYPE.HEADER.ordinal()){ //Header

        final ViewHolderHeader holder1 = (ViewHolderHeader)holder;

        CalendarHeader header = (CalendarHeader)item;

        Log.d(TAG,"Entrou header: "+header.getDate());

        //Mete a colSpan a 2
        if (lp.colSpan != 2)
            lp.colSpan = 2;

        lp.height = 100; //Event forcing the height doesn't work
        view.setLayoutParams(lp);

    }else{ //Show

        final ViewHolder holder1 = (ViewHolder)holder;
        UpcomingShow show = (UpcomingShow)item;

        if (lp.colSpan != 1)
            lp.colSpan = 1;

        view.setLayoutParams(lp);

    }

}

Fragment layout:

    <org.lucasr.twowayview.widget.TwoWayView
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/spanGrid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    style="@style/TwoWayView"
    app:twowayview_layoutManager="SpannableGridLayoutManager"
    app:twowayview_numColumns="2"/>

What i'm doing wrong ? I'm not used to the recycler view way of doing things, i must be missing something. Teste with Android 4.1.1