I'm trying to change the height and the width from fixed to match parent or wrap content when images are loaded into the recycler view https://stackoverflow.com/a/67860281/15537898 here is the answer I'm trying to implement but after it gives me this error
Attempt to invoke virtual method 'int android.graphics.Bitmap.getHeight()' on a null object reference
Fragment_Search.java
ShapeableImageView siv;
Bitmap bm;
int height = bm.getHeight();
int width = bm.getWidth();
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_search, container, false);
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
postRecyclerView = view.findViewById(R.id.postRecyclerView);
siv = view.findViewById(R.id.imageView);
ViewGroup.LayoutParams params = siv.getLayoutParams();
params.height = height;
params.width = width;
postRecyclerView.setLayoutManager(
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL)
);
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
getData();
mUploads = new ArrayList<>();
postsAdapter = new PostAdapter_Search(getContext(), mUploads);
postRecyclerView.setAdapter(postsAdapter);
return view;
}