我想使用Horizontal View Pager创建一些滚动视图.左视图必须具有全屏宽度,但只有四分之一宽度(它将是Dolphin浏览器中的垂直面板).有可能这样做吗?我改变android:layout_width了正确的布局,但它没有用.
我的代码:
public class TestActivity extends FragmentActivity {
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_view);
MyPagerAdapter adapter = new MyPagerAdapter();
ViewPager pager = (ViewPager) findViewById(R.id.panelPager);
pager.setAdapter(adapter);
pager.setCurrentItem(0);
}
}
Run Code Online (Sandbox Code Playgroud)
main_view.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/panelPager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
MyPagerAdapter.java
public class MyPagerAdapter extends PagerAdapter {
@Override
public int getCount() {
return 2;
}
@Override
public Object instantiateItem(final View collection, final int position) {
LayoutInflater inflater =
(LayoutInflater) collection.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId …Run Code Online (Sandbox Code Playgroud)