I have a navigation drawer and ViewPager
where one can chose an object from a list in the drawer. When clicked/ touched I want to add that image to the active slide in the ViewPager
.
I have made a method addObjectToSlide()
which does that, but the image is attached to wrong View. When I slide from one page to another, the image is stuck on top. Also when I open the drawer, the image is over that.
Here is my code:
private void addObjectToSlide(int pageNumber, int position) {
ViewGroup rootView = (ViewGroup) findViewById(R.id.scroll_view_slides).getRootView();
RelativeLayout.LayoutParams imParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
imParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
ImageView iv = new ImageView(rootView.getContext());
switch (pageNumber) {
case 0 :
iv.setImageDrawable(getResources().obtainTypedArray(R.array.p1_object).getDrawable(position));
break;
default:
// add later
}
rootView.addView(iv, imParams);
}
scroll_view_slides
is the RelativeLayout
id for fragment_screen_slide_page.xml
.