下面列出了android.view.View#getMinimumHeight ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static int getMinHeight(View view)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
{
return view.getMinimumHeight();
} else
{
try
{
Field minHeight = view.getClass().getField("mMinHeight");
minHeight.setAccessible(true);
return (int) minHeight.get(view);
} catch (Exception e)
{
}
}
return 0;
}
public static void expand(final View v, @Nullable Animation.AnimationListener listener) {
final int targetHeight;
if (v.getMinimumHeight() != 0) {
targetHeight = v.getMinimumHeight();
} else {
v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
targetHeight = v.getMeasuredHeight();
}
v.getLayoutParams().height = 0;
v.setVisibility(View.VISIBLE);
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = interpolatedTime == 1
? ViewGroup.LayoutParams.WRAP_CONTENT
: (int) (targetHeight * interpolatedTime);
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
if (listener != null) a.setAnimationListener(listener);
a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density));
v.startAnimation(a);
}
public static int getMinHeight(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return view.getMinimumHeight();
} else {
return getValue(view, METHOD_GET_MIN_HEIGHT);
}
}
/**
* View Measure
* @param view 待计算 View
* @param widthMeasureSpec horizontal space requirements as imposed by the parent
* @param heightMeasureSpec vertical space requirements as imposed by the parent
* @param maximumWidth maximum Width
* @param maximumHeight maximum Height
* @param defaultValue 默认值
* @return measure space Array
*/
public static int[] viewMeasure(final View view, final int widthMeasureSpec, final int heightMeasureSpec,
final int maximumWidth, final int maximumHeight, final int defaultValue) {
int minimumWidth = 0, minimumHeight = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
minimumWidth = view.getMinimumWidth();
minimumHeight = view.getMinimumHeight();
}
return viewMeasure(widthMeasureSpec, heightMeasureSpec,
minimumWidth, maximumWidth, minimumHeight, maximumHeight, defaultValue);
}
/**
* 获取 View 最小高度
* @param view View
* @return View 最小高度
*/
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
public static int getMinimumHeight(final View view) {
if (view != null) {
return view.getMinimumHeight();
}
return 0;
}
public static int getMinimumHeight(View view) {
return view.getMinimumHeight();
}
public static int getMinimumHeight(View view) {
return view.getMinimumHeight();
}