My Recycler Item which inflate in onCreateViewHolder
v.getLayoutParams().width = parent.getMeasuredWidth() / 2;
v.getLayoutParams().height = parent.getMeasuredWidth() / 2;
This is my code for adjusting height of recycle view element based on actual aspect-ration required.
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.adapter_offers, parent, false);
int width = parent.getMeasuredWidth();
float height = (float) width / Config.ASPECT_RATIO;//(Width/Height)
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) itemView.getLayoutParams();
params.height = Math.round(height);
itemView.setLayoutParams(params);
return new MyViewHolder(itemView);
}