henryblue / TvRecyclerView

A custom RecyclerView for Android TV end
Apache License 2.0
7 stars 4 forks source link

some bug #8

Closed LiuStangMing closed 6 years ago

LiuStangMing commented 6 years ago

I am Chinese. My English is not good. I'm sorry I use translation. With your TvRecyclerView , the module focus-vertical layout will have problems when you add an item below the head layout. For example, if the textview is not centered, the background of framLayout will overflow.

henryblue commented 6 years ago

你可以用中文具体描述一遍.

LiuStangMing commented 6 years ago

就是在module focus-vertical的那个activity里面,我尝试在TvRecyclerView的adapter里面添加了不同类型的布局,就是分类,发现主布局超过一定数量的item会出现显示问题,比如item的那个textview不居中了,或者背景超出边框了。

henryblue commented 6 years ago

把你设置的startIndex, itemRowSize, itemColumnSize贴一下, 因为不管你item设置大小还是具体值, 在ModuleLayoutManager中, 会根据startIndex, itemRowSize, itemColumnSize对item的大小进行具体设置,这个可能会导致item中的元素显示有问题

LiuStangMing commented 6 years ago

我就在原来的里面 最前面 加了一位数 startIndex 0 ,itemRowSize 1 , itemColumnSize 4

henryblue commented 6 years ago

startIndex ,itemRowSize, itemColumnSize设置不对, 你可能还不理解这三个值的作用, 稍后我会更新到readme中

LiuStangMing commented 6 years ago

不,我已经理解了,startindex是 起始位置 itemRowSize 高度的占比 itemColumnSize 宽度的占比

LiuStangMing commented 6 years ago

不好意思,因为加了第一位,导致后面的也有变化,我忘了,我发下我的给你 mStartIndex = {0, 4, 5, 7, 11, 12, 13, 15, 16, 17, 18, 24, 25, 26, 27, 29, 30, 31}; mItemRowSizes = {1, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1}; mItemColumnSizes = {4, 1, 2, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1};

henryblue commented 6 years ago

你adapter中如何设置的, 贴一下

LiuStangMing commented 6 years ago

@Override public int getItemViewType(int position) { if (position == 0) { return TYPE_TITLE; } return TYPE_CONTENT; }

加上类型判断 写多一个ViewHolder,item布局里面就简单的一个LinearLayout,内部一个TextView

henryblue commented 6 years ago

我将第一的item设置成不同的布局, 其他的还是以前的, 没有问题, 你讲你的布局贴一下

LiuStangMing commented 6 years ago

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="100dp" android:clipChildren="false" android:clipToPadding="false" android:gravity="center">

<TextView
    android:textSize="30sp"
    android:textColor="#ffffff"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/id_item_title"/>

这个是title布局

public class ModuleAdapter extends RecyclerView.Adapter {

private static final int TYPE_TITLE = 0;
private static final int TYPE_CONTENT = 1;

private Context mContext;
private int mItemCount;

ModuleAdapter(Context context, int itemCount) {
    mContext = context;
    mItemCount = itemCount;
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    if (viewType == TYPE_TITLE) {
        return new TitleViewHolder(View.inflate(mContext, R.layout.title_viewholder, null));
    } else if (viewType == TYPE_CONTENT) {
        return new RecyclerViewHolder(View.inflate(mContext, R.layout.module_item_recyclerview, null));
    }
    return null;
}

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

    if (getItemViewType(position) == TYPE_TITLE) {
        TitleViewHolder viewHolder = (TitleViewHolder) holder;
        viewHolder.textView.setText("title " + position);
    }

    if (getItemViewType(position) == TYPE_CONTENT) {
        final RecyclerViewHolder viewHolder = (RecyclerViewHolder) holder;
        viewHolder.mName.setText(position + "");
        GradientDrawable drawable = (GradientDrawable) viewHolder.mFrameLayout.getBackground();
        drawable.setColor(ContextCompat.getColor(mContext, ContantUtil.getRandColor()));
    }
}

@Override
public int getItemCount() {
    return mItemCount;
}

@Override
public int getItemViewType(int position) {
    if (position == 0) {
        return TYPE_TITLE;
    }
    return TYPE_CONTENT;
}

private class RecyclerViewHolder extends RecyclerView.ViewHolder {

    FrameLayout mFrameLayout;
    TextView mName;

    RecyclerViewHolder(View itemView) {
        super(itemView);
        mName = (TextView) itemView.findViewById(R.id.tv_item_tip);
        mFrameLayout = (FrameLayout) itemView.findViewById(R.id.fl_main_layout);
    }
}

private class TitleViewHolder extends RecyclerView.ViewHolder {

    private TextView textView;

    public TitleViewHolder(View itemView) {
        super(itemView);

        textView = itemView.findViewById(R.id.id_item_title);
        textView.setFocusable(false);
    }
}

}

这是adapter代码

henryblue commented 6 years ago

没有问题, textview在左上角, 想要居中靠下, 设置
android:layout_gravity="bottom" android:gravity="center" 没有出现背景超出边框的问题

LiuStangMing commented 6 years ago

能麻烦加下QQ吗?我截个问题图给你看下。

LiuStangMing commented 6 years ago

你尝试下多添加几个item,当超过一定数量后,后面的item会出现显示问题的。

henryblue commented 6 years ago

已经修改, 分辨率导致