02-24 03:18:22.859: E/AndroidRuntime(2992): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.TableRow$LayoutParams
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.TableRow.mapIndexAndColumns(TableRow.java:164)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.TableRow.getVirtualChildCount(TableRow.java:149)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.TableRow.getColumnsWidths(TableRow.java:289)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.TableLayout.findLargestCells(TableLayout.java:508)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.TableLayout.measureVertical(TableLayout.java:473)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.TableLayout.onMeasure(TableLayout.java:439)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.view.View.measure(View.java:15848)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.view.View.measure(View.java:15848)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.view.View.measure(View.java:15848)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.view.View.measure(View.java:15848)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5012)
02-24 03:18:22.859: E/AndroidRuntime(2992): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
02-24 03:18:22.859: E/AndroidRuntime(2992): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2189)
出错代码:
mPager = (ViewPager) findViewById(R.id.vPager);
//获取屏幕像素相关信息
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
//根据屏幕信息设置ViewPager广告容器的宽高
mPager.setLayoutParams(new LayoutParams(dm.widthPixels-120, dm.heightPixels));
解决办法:ViewPager需要设置在LinearLayout布局中,并且代码如下
mPager = (ViewPager) findViewById(R.id.vPager);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
//根据屏幕信息设置ViewPager广告容器的宽高
mPager.setLayoutParams(new LinearLayout.LayoutParams(dm.widthPixels-120, dm.heightPixels));