我有以下的代码,但我得到一个异常如何以编程方式设置ViewPager layoutParams?
java.lang.ClassCastException: android.support.v4.view.ViewPager $的LayoutParams不能转换到 android.view.ViewGroup $ MarginLayoutParams
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.question_details_full_photo_view_pager);
Bundle bundle = getIntent().getExtras();
ArrayList<String> imageUrls = bundle.getStringArrayList("imageUrls");
ImagePagerAdapter imagePagerAdapter = new ImagePagerAdapter(this, imageUrls, true);
android.support.v4.view.ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager_full_photo);
android.support.v4.view.ViewPager.LayoutParams layoutParams = new LayoutParams();
layoutParams.width = LayoutParams.MATCH_PARENT;
layoutParams.height = LayoutParams.MATCH_PARENT;
viewPager.setLayoutParams(layoutParams);
viewPager.setAdapter(imagePagerAdapter);
}
您使用的是什么进口产品? – g00dy
快速解决方案可以(但不是必须)设置:改为'android.support.v4.view.ViewPager.LayoutParams layoutParams = new LayoutParams();' - >到'android.support.v4.view.ViewGroup.LayoutParams layoutParams = new LayoutParams();' – g00dy