XML
<LinearLayout
android:id="@+id/cotainer_more"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/color_white"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/container_lazada"
android:layout_width="match_parent"
android:layout_height="50dp">
<FrameLayout
android:id="@+id/img_lazada"
android:layout_width="45dp"
android:layout_height="match_parent"
android:layout_marginLeft="40dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@mipmap/lazada_icon" />
</FrameLayout>
<TextView
android:id="@+id/tv_lazada"
style="@style/Style_Text_Size_14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/img_lazada"
android:text="Lazada"
android:textColor="@color/color_list_text"
android:textStyle="bold" />
<ImageView
android:id="@+id/img_more_anchor_lazada"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="40dp"
android:src="@mipmap/more_1" />
<TextView
android:id="@+id/tv_hint_authenticate_lazada"
style="@style/Style_Text_Size_14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@id/img_more_anchor_lazada"
android:text="@string/tidak_sempurna"
android:textColor="@color/color_hint_text" />
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:layout_alignParentBottom="true"
android:background="@color/color_parting_line" />
</RelativeLayout>
</LinearLayout>
Java代码
@BindView(R.id.cotainer_more)
LinearLayout cotainerMore;
private boolean isClickMore;
containerMore.setOnClickListener(v -> {
if (!isClickMore) {
setExpandAnimation(0, SizeUtils.dp2px(50), cotainerMore);
isClickMore = true;
} else {
setExpandAnimation(SizeUtils.dp2px(50), 0, cotainerMore);
isClickMore = false;
}
});
private void setExpandAnimation(int startSize, int endSize, final View view) {
ValueAnimator animator = ValueAnimator.ofInt(startSize, endSize);
animator.setDuration(200);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Integer value = (Integer) animation.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.height = value;
view.setLayoutParams(layoutParams);
}
});
animator.start();
}
效果: