好的球員,我需要找到一種方法,將距離改爲上的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