In my application, I use ViewPager with FragmentStatePagerAdapter to display 4 different layouts. Layout 1, 3, 4 consists of a ListView, and the second layout contains a SurfaceView Camera. Now, when I scroll the horizontal camera at both edges, you flicker.
I search on google and find different solutions. like 1) providing minus margin using android: layout_gravity = "center". 2) viewPager.requestTransparentRegion (viewPager);
Here, in the first case, it works well for the first time, but when you return from the resume, it cuts to the right, showing a black rectangle.
I also tried with a different parent layout, but the same scenario and tried to give a margin programmatically, but could not find a solution.
Here is my xml camera.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_gravity="center"
android:layout_marginRight="-100dp"
android:layout_marginLeft="-100dp"
android:layout_height="match_parent"
android:visibility="visible" />
</LinearLayout>
and here is my fragment adapter.
public class DashboardAdapter extends FragmentStatePagerAdapter {
public DashboardAdapter(FragmentManager fm) {
super(fm);
fragmentList = new ArrayList<>();
fragmentList.add(new InboxFragment());
fragmentList.add(new CameraFragment());
fragmentList.add(new ContactFragment());
fragmentList.add(new AddFriendsFragmnet());
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return InboxFragment.newInstance(position);
case 1:
return CameraFragment.newInstance(position);
case 2:
return ContactFragment.newInstance(position);
case 3:
return AddFriendsFragmnet.newInstance(position);
default:
return CameraFragment.newInstance(position);
}
}
@Override
public int getCount() {
return 4;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
return fragment;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
}
}
.