You can try to do the following:
In the image of interest in the layout indicate
android:adjustViewBounds="true" android:maxHeight="250dp" (нужная вам высота)
in the MainActivity specify the method that will calculate this height
public int getWindowHeightForImage() { return (int) Math.round(getWindowManager().getDefaultDisplay().getHeight() * 0.4); }
In the adapter, set a variable for the height (part of the code removed, only the part directly relevant to the question is shown)
public class NewsFeedRecyclerViewAdapter extends RecyclerView.Adapter<NewsFeedRecyclerViewAdapter.ViewHolder> { private int mImageViewHeight; // вот эта переменная public NewsFeedRecyclerViewAdapter(Context context, RealmResults<News> items, int imageViewHeight) { mImageViewHeight = imageViewHeight; }
Specify this value in the holder
class ViewHolder extends RecyclerView.ViewHolder { ImageView mNewsImage; public ViewHolder(View itemView) { super(itemView); mNewsImage = (ImageView) itemView.findViewById(R.id.one_news_main_picture); mNewsImage.getLayoutParams().height = mImageViewHeight; // наша переменная
and transfer to a fragment of our one item from the list
private void setAdapter() { mAdapter = new NewsFeedRecyclerViewAdapter(getActivity(), results, ((MainActivity) getActivity()).getWindowHeightForImage());}
I understand that I have somehow explained it very clumsily now, but it works.