4
在我的應用程序中,我使用ViewPager和FragmentStatePagerAdapter來顯示4種不同的佈局。 佈局1,3,4由ListView組成,第二個佈局包含SurfaceView相機。現在,當我在兩邊水平滾動相機時,會出現閃爍現象。相機SurfaceView閃爍在視圖中尋呼時滾動
我在谷歌搜索,並找到不同的解決方案。像 1)給android:layout_gravity =「center」減去餘量。 2)viewPager.requestTransparentRegion(viewPager);
這裏在第一種情況下,它在第一時間效果很好,但是當從簡歷中恢復時,它會從右側顯示黑色矩形切割。
另外我也嘗試了不同的父級佈局,但發生了相同的場景 ,並試圖以編程方式給出保證金,但找不到任何解決方案。
這是我的相機xml。
<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>
這裏是我的片段適配器。
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) {
}
}
任何幫助將是太多了感謝。
嗨,最後經過這麼多的東西,我已經解決了這個問題,通過TextureView替換SurfaceView。下面的鏈接可以幫助我用相機「TextureView」。 [鏈接](http://www.tutorialspoint.com/android/android_textureview.htm)。如果任何機構比我能分享我在項目中使用的實際代碼的和平。 – Neo
如果您找到了解決方案,請不要等待有人來問您,只需將其作爲回答發佈並接受/標記爲答案。如果你自己想出一個解決方案,這沒關係。 :) – Sufian