|
|
@@ -3,11 +3,14 @@ package com.webrain.dailypay.ui.widget;
|
|
|
import android.animation.Animator;
|
|
|
import android.animation.ValueAnimator;
|
|
|
import android.content.Context;
|
|
|
+import android.content.res.TypedArray;
|
|
|
import android.util.AttributeSet;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
|
+import com.webrain.dailypay.R;
|
|
|
+
|
|
|
public class ShrinkAnimationLayout extends LinearLayout {
|
|
|
|
|
|
public ShrinkAnimationLayout(Context context) {
|
|
|
@@ -20,18 +23,21 @@ public class ShrinkAnimationLayout extends LinearLayout {
|
|
|
|
|
|
public ShrinkAnimationLayout(Context context, AttributeSet attrs, int defStyle) {
|
|
|
super(context, attrs, defStyle);
|
|
|
- initView();
|
|
|
+ initView(context, attrs);
|
|
|
}
|
|
|
|
|
|
private View layoutView;
|
|
|
private int viewHeight;
|
|
|
+ private int xmlHeight;
|
|
|
private boolean isExpand;
|
|
|
private boolean isInitShow;
|
|
|
private long animationDuration;
|
|
|
private boolean isAnimation; //是否正在动画中
|
|
|
private OnAnimationListener onAnimationListener;
|
|
|
|
|
|
- private void initView() {
|
|
|
+ private void initView(Context context, AttributeSet attrs) {
|
|
|
+ TypedArray ta = context.obtainStyledAttributes(attrs, com.webrain.baselibrary.R.styleable.ShrinkAnimationLayout);
|
|
|
+ xmlHeight = ta.getDimensionPixelSize(R.styleable.ShrinkAnimationLayout_salHeight, 0);
|
|
|
layoutView = this;
|
|
|
isExpand = true;
|
|
|
animationDuration = 300;
|
|
|
@@ -39,7 +45,7 @@ public class ShrinkAnimationLayout extends LinearLayout {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param isExpand 初始状态是否折叠
|
|
|
+ * @param isExpand 初始状态是否展开
|
|
|
*/
|
|
|
public void initExpand(boolean isExpand) {
|
|
|
this.isExpand = isExpand;
|
|
|
@@ -64,18 +70,25 @@ public class ShrinkAnimationLayout extends LinearLayout {
|
|
|
* View.post() 的 runnable 对象中的方法会在 View 的 measure、layout 等事件后触发
|
|
|
*/
|
|
|
private void setViewDimensions() {
|
|
|
- layoutView.post(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- if (viewHeight <= 0) {
|
|
|
- viewHeight = layoutView.getMeasuredHeight();
|
|
|
- }
|
|
|
- if (isInitShow)
|
|
|
- if (!isExpand) {
|
|
|
- animateToggle(10);
|
|
|
+ if (xmlHeight > 0) {
|
|
|
+ viewHeight = xmlHeight;
|
|
|
+ isExpand = false;
|
|
|
+ } else {
|
|
|
+ layoutView.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (viewHeight <= 0) {
|
|
|
+ viewHeight = layoutView.getMeasuredHeight();
|
|
|
}
|
|
|
- }
|
|
|
- });
|
|
|
+ if (isInitShow)
|
|
|
+ if (!isExpand) {
|
|
|
+ animateToggle(10);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public static void setViewHeight(View view, int height) {
|