ObjectAnimator.ofFloat(myObject, "translationY", -myObject.getHeight()).start();
ValueAnimator colorAnim = ObjectAnimator.ofInt(this, "backgroundColor", /*Red*/0xFFFF8080, /*Blue*/0xFF8080FF);
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); |
AppCompat-v7:21 provides a very useful way of dealing with pressed/focused/activated states maintaining backwards compatibility downto API-7, but there's a small issue (big for some) with the default selectableItemBackground: It uses some PNGs and/or default values for API<21. | |
The main reason is that android drawable resource definitions (prior API 21) CANNOT use theme attributes at all, so there's no way of making something like: | |
<shape android:shape="rectangle"> | |
<solid android:color="?attr/colorControlHighlight" /> | |
</shape> | |
For this, I've put this simple mockup on how to give your app better drawables that the appcompat defaults. |