我试图找到一些帮助,为我的应用程序包含一个平板电脑模式。它使用带有4个碎片的ViewPager,我想要做的是7“显示器和10”显示器的平板电脑模式。我想在4平方的布局中显示我的片段,而不是大视图寻呼机。在7“我希望显示2平方布局。我只是想找到一个如何做到这一点的好例子。这是我的下面的viewpager源代码和片段的示例。此源使用库ActionBarSherlock和ViewPagerIndicator。
public class MainActivity extends SherlockFragmentActivity {
private ViewPager mPager;
private TitlePageIndicator mIndicator;
private MainPagerAdapter mAdapter;
private List<Fragment> mFragments;
public static final String PREFS_NAME = "MyPrefsFile1";
public CheckBox dontShowAgain;
private static final String FRAGMENT1 = EnlightenFragment.class.getName();
private static final String FRAGMENT2 = CommunityFragment.class.getName();
private static final String FRAGMENT3 = SupportFragment.class.getName();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a_main);
getSupportActionBar().setDisplayShowTitleEnabled(false);
// add fragments
mFragments = new ArrayList<Fragment>();
mFragments.add(Fragment.instantiate(this, FRAGMENT1));
mFragments.add(Fragment.instantiate(this, FRAGMENT2));
mFragments.add(Fragment.instantiate(this, FRAGMENT3));
// adapter
mAdapter = new MainPagerAdapter(getSupportFragmentManager(), mFragments);
// pager
mPager = (ViewPager) findViewById(R.id.view_pager);
mPager.setOffscreenPageLimit(4);
mPager.setAdapter(mAdapter);
// indicator
mIndicator = (TitlePageIndicator) findViewById(R.id.title_indicator);
mIndicator.setViewPager(mPager);
}
}
public class MainPagerAdapter extends FragmentPagerAdapter {
private List<Fragment> mFragments;
private String[] titles = new String[] {"System", "Community", "Support" };
private int mCount = titles.length;
public MainPagerAdapter(FragmentManager fm, List<Fragment> f) {
super(fm);
mFragments = f;
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
@Override
public int getCount() {
return mCount;
}
@Override
public CharSequence getPageTitle(int position) {
return titles[position];
}
}
public class SupportFragment extends SherlockFragment {
WebView web;
static ProgressBar progressBar;
Context context;
@Override
public View onCreateView(LayoutInflater inf, ViewGroup grp, Bundle icicle) {
View v = inf.inflate(R.layout.activity_main, grp, false);
//mList = (ListView) v.findViewById(R.id.listView1);
web = (WebView) v.findViewById(R.id.webView);
progressBar = (ProgressBar) v.findViewById(R.id.progressBar1);
setHasOptionsMenu(true);
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (savedInstanceState != null)
((WebView) getSherlockActivity().findViewById(R.id.webView))
.restoreState(savedInstanceState);
web.setWebViewClient(new SpecialWebView(progressBar));
web.setWebChromeClient(new SpecialWebChromeClient(progressBar));
// Progress Bar - End
web.setWebViewClient(new myWebClient());
//progressBar = (ProgressBar) getSherlockActivity().findViewById(R.id.progressBar1);
web.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
progressBar.setProgress(progress);
}
});
WebSettings websettings = web.getSettings();
websettings.setBuiltInZoomControls(false);
web.setBackgroundColor(Color.parseColor("#f2f2f2"));
// websettings.setUseWideViewPort(position == 0 ? true : false);
websettings.setUseWideViewPort(true);
websettings.setJavaScriptEnabled(true);
websettings.setAllowFileAccess(true);
websettings.setDomStorageEnabled(true);
websettings.setLoadWithOverviewMode(true);
websettings.setSavePassword(true);
websettings.setBuiltInZoomControls(true);
web.loadUrl(url);
setHasOptionsMenu(true);
}