android viewpager问题 50
点击按钮增加一个页面,哪里出错了,求解!publicclassMainActivityextendsActivity{privateViewPagerviewPager;...
点击按钮增加一个页面,哪里出错了,求解!
public class MainActivity extends Activity {
private ViewPager viewPager;
private MyAdapter adapter;
private static List<View> views;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.viewpager);
// 使用pageTitleStrip时标签无点击响应
// pageTitle = (PagerTitleStrip)findViewById(R.id.pagertitle);
views = new ArrayList<View>();
LayoutInflater inflater = LayoutInflater.from(this);
inflater = getLayoutInflater().from(this);
View view0 = inflater.inflate(R.layout.view0, null);
views.add(view0);
btn = (Button) view0.findViewById(R.id.add);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
View view = null;
MainActivity.views.add(view);
adapter.notifyDataSetChanged();
}
});
adapter = new MyAdapter(this, views);
viewPager.setAdapter(adapter);
}
} 展开
public class MainActivity extends Activity {
private ViewPager viewPager;
private MyAdapter adapter;
private static List<View> views;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.viewpager);
// 使用pageTitleStrip时标签无点击响应
// pageTitle = (PagerTitleStrip)findViewById(R.id.pagertitle);
views = new ArrayList<View>();
LayoutInflater inflater = LayoutInflater.from(this);
inflater = getLayoutInflater().from(this);
View view0 = inflater.inflate(R.layout.view0, null);
views.add(view0);
btn = (Button) view0.findViewById(R.id.add);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
View view = null;
MainActivity.views.add(view);
adapter.notifyDataSetChanged();
}
});
adapter = new MyAdapter(this, views);
viewPager.setAdapter(adapter);
}
} 展开
1个回答
2015-04-02
展开全部
显示问题:
1、设置ScrollView的fillViewPort为true
2、设置ViewPager的layout_height为一个固定高度,比如:100dip
冲突问题:
不过ViewPager显示出来以后,还有另外一个冲突:ViewPager左右不能滑动了!是的,因为这个事件其实已经被外层的ScrollView截获!
重写ScrollView控件!
1、设置ScrollView的fillViewPort为true
2、设置ViewPager的layout_height为一个固定高度,比如:100dip
冲突问题:
不过ViewPager显示出来以后,还有另外一个冲突:ViewPager左右不能滑动了!是的,因为这个事件其实已经被外层的ScrollView截获!
重写ScrollView控件!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询