我用custom ExpandableListView
创建了一个应用程序。工作正常。但是我已经读到在Jelly Bean setIndicatorBounds
中效果不佳。我与:
minSdkVersion:14
targetSdkVersion:18
我已经尝试过了,但是它给了我一个错误:
调用需要API级别18(当前最小值为14):android.widget.ExpandableListView#setIndicatorBoundsRelative
DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
int anchoPantalla = metrics.widthPixels;
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
expListView.setIndicatorBounds(anchoPantalla - GetDipsFromPixel(40),
anchoPantalla - GetDipsFromPixel(10));
} else {
expListView.setIndicatorBoundsRelative(anchoPantalla - GetDipsFromPixel(40),
anchoPantalla - GetDipsFromPixel(10));
}
如何解决错误,我的代码在Jelly Bean中正常工作?谢谢
最佳答案
...
DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
int anchoPantalla = metrics.widthPixels;
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
expListView.setIndicatorBounds(anchoPantalla - GetDipsFromPixel(40),
anchoPantalla - GetDipsFromPixel(10));
} else {
JB_setIndicatorBoundsRelative(anchoPantalla - GetDipsFromPixel(40),
anchoPantalla - GetDipsFromPixel(10));
}
}
...
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private void JB_setIndicatorBoundsRelative(int left, int right)
{
expListView.setIndicatorBoundsRelative(left, right);
}