I am using the listview add/remove footer for listview cross app in android version 4.3?
- Android 4.4 以上 ListView 正常显示AddFooterView()内容
- Android 4.3 以下 ListView 反而显示不出AddFooterView内容
ShapeDrawable rectChecked = new ShapeDrawable(new RectShape()); | |
rectChecked.getPaint().setColor(0xfffffff); | |
rectChecked.getPaint().setStyle(Paint.Style.STROKE); | |
rectChecked.getPaint().setStrokeWidth(strokeWidth); | |
rectChecked.setIntrinsicHeight(bitmap.getHeight() + strokeWidth); | |
rectChecked.setIntrinsicWidth(bitmap.getWidth() + strokeWidth); | |
Drawable[] drawableArray = new Drawable[]{bmp,rectChecked}; | |
LayerDrawable layerChecked = new LayerDrawable(drawableArray); |
//StateList drawable | |
StateListDrawable states = new StateListDrawable(); | |
states.addState(new int[]{android.R.attr.state_checked},layerChecked); | |
states.addState(new int[]{},layerUnchecked); |
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){ | |
setBackground(states); | |
}else{ | |
setBackgroundDrawable(states); | |
} | |
// 查看SDK_INT对应的版本号 | |
// https://developer.android.com/guide/topics/manifest/uses-sdk-element.html |
int width = 72; | |
int height = 96; | |
float scale = getResources().getDisplayMetrics().density; | |
int pixelsWidth = (int) (width * scale + 0.5f); | |
int pixelsHeight = (int) (height * scale + 0.5f); |
public static int compareVersion(String version1, String version2) { | |
if (TextUtils.isEmpty(version1)) { | |
return -1; | |
} | |
if (TextUtils.isEmpty(version2)) { | |
return -1; | |
} | |
if (!TextUtils.isEmpty(version1) && !TextUtils.isEmpty(version2)) { | |
try { |
if (Util.getListSize(hotellist) > 0) { | |
int index = hotellist.indexOf(h); | |
hotellist.remove(index); | |
hotellist.add(0, h); | |
} |
/** | |
* Sets ListView height dynamically based on the height of the items. | |
* | |
* @param listView to be resized | |
* @return true if the listView is successfully resized, false otherwise | |
*/ | |
public static boolean setListViewHeightBasedOnItems(ListView listView) { | |
ListAdapter listAdapter = listView.getAdapter(); | |
if (listAdapter != null) { |
/** | |
* 计算view高度 | |
* | |
* @param v | |
* @return | |
*/ | |
public static int getViewHeight(View v) { | |
int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(Constants.DEVICE_WIDTH, View.MeasureSpec.EXACTLY); | |
int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); | |
v.measure(widthMeasureSpec, heightMeasureSpec); |