好的球员,我需要找到一种方法,将距离改为上的RecyclerView方向变化上,因为它在水平和垂直方向的不同,我得到这个工作的项目,onBindViewHolder但我还需要设置为RecyclerView的参数,可以将下面的代码不起作用:获取RecyclerView例如onCreateViewHolder设置PARAMS
public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
final View view = this.layoutInflater.inflate(R.layout.row_item, parent, false);
// Create layout params for the RecyclerView
RecyclerView.LayoutParams params
= new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.MATCH_PARENT);
// Set them margins
params.setMargins(0, spanCount * 500, 0, spanCount * 10);
// Get reference, this doesn't work
RecyclerView rv = (RecyclerView) parent.getChildAt(0); // Doesn't work
rv.setLayoutParams(params); // <- Throws NPE
return new ItemViewHolder(view);
}
我也试着铸造RecyclerView父和看法,也不能工作。
使用RelativeLayout.LayoutParams类不RecyclerView.LayoutParams。 – Seishin