日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

属性动画的应用

發布時間:2025/4/16 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 属性动画的应用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><!-- 上面部分 --><RelativeLayout android:background="#ffffff"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="4dp" ><ImageView android:id="@+id/app_detail_safe_iv_arrow"android:layout_width="15dp"android:layout_height="15dp"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:layout_marginRight="15dp"android:src="@drawable/arrow_down" /><!-- 圖片容器 --><LinearLayout android:id="@+id/app_detail_safe_pic_container"android:layout_width="wrap_content"android:layout_height="wrap_content"android:orientation="horizontal"android:paddingBottom="5dp"android:paddingLeft="10dp"android:paddingTop="5dp" ></LinearLayout></RelativeLayout><!-- 下面部分 --><LinearLayout android:background="#ffffff"android:id="@+id/app_detail_safe_des_container"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical" ></LinearLayout></LinearLayout> public class AppDetailSafeHolder extends BaseHolder<AppInfoBean> implements OnClickListener {@ViewInject(R.id.app_detail_safe_pic_container)LinearLayout mContainerPic;@ViewInject(R.id.app_detail_safe_des_container)LinearLayout mContainerDes;@ViewInject(R.id.app_detail_safe_iv_arrow)ImageView mIvArrow;private boolean isOpen = true;@Overridepublic View initHolderView() {View view = View.inflate(UIUtils.getContext(), R.layout.item_app_detail_safe, null);ViewUtils.inject(this, view);view.setOnClickListener(this);return view;}@Overridepublic void refreshHolderView(AppInfoBean data) {List<AppInfoSafeBean> safeBeans = data.safe;for (AppInfoSafeBean appInfoSafeBean : safeBeans) {ImageView ivIcon = new ImageView(UIUtils.getContext());BitmapHelper.display(ivIcon, URLS.IMAGEBASEURL + appInfoSafeBean.safeUrl);mContainerPic.addView(ivIcon);LinearLayout ll = new LinearLayout(UIUtils.getContext());// 描述圖標ImageView ivDes = new ImageView(UIUtils.getContext());BitmapHelper.display(ivDes, URLS.IMAGEBASEURL + appInfoSafeBean.safeDesUrl);// 描述內容TextView tvDes = new TextView(UIUtils.getContext());tvDes.setText(appInfoSafeBean.safeDes);if (appInfoSafeBean.safeDesColor == 0) {tvDes.setTextColor(UIUtils.getColor(R.color.app_detail_safe_normal));} else {tvDes.setTextColor(UIUtils.getColor(R.color.app_detail_safe_warning));}tvDes.setGravity(Gravity.CENTER);// 加點間距int padding = UIUtils.dip2Px(5);ll.setPadding(padding, padding, padding, padding);ll.addView(ivDes);ll.addView(tvDes);mContainerDes.addView(ll);}// 默認折疊toggle(false);}@Overridepublic void onClick(View v) {toggle(true);}private void toggle(boolean isAnimation) {if (isOpen) {// 折疊/**mContainerDes高度發生變化應有的高度-->0*/mContainerDes.measure(0, 0);int measuredHeight = mContainerDes.getMeasuredHeight();int start = measuredHeight;// 動畫的開始高度int end = 0;// 動畫的結束高度if (isAnimation) {doAnimation(start, end);} else {// 直接修改高度LayoutParams params = mContainerDes.getLayoutParams();params.height = end;mContainerDes.setLayoutParams(params);}} else {// 展開/**mContainerDes高度發生變化0-->應有的高度*/mContainerDes.measure(0, 0);int measuredHeight = mContainerDes.getMeasuredHeight();int end = measuredHeight;// 動畫的開始高度int start = 0;// 動畫的結束高度if (isAnimation) {doAnimation(start, end);} else {LayoutParams params = mContainerDes.getLayoutParams();params.height = end;mContainerDes.setLayoutParams(params);}}// 箭頭的旋轉動畫if (isAnimation) {// 有折疊動畫的時候if (isOpen) {ObjectAnimator.ofFloat(mIvArrow, "rotation", 180, 0).start();} else {ObjectAnimator.ofFloat(mIvArrow, "rotation", 0, 180).start();}}isOpen = !isOpen;}public void doAnimation(int start, int end) {ValueAnimator animator = ValueAnimator.ofInt(start, end);animator.start();// 開始動畫animator.addUpdateListener(new AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator value) {int height = (Integer) value.getAnimatedValue();// 通過layoutParams,修改高度LayoutParams params = mContainerDes.getLayoutParams();params.height = height;mContainerDes.setLayoutParams(params);}});}} <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:padding="4dp" ><LinearLayout android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@android:color/white"android:orientation="vertical"android:padding="5dp" ><!-- 簡介 --><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:singleLine="true"android:text="簡介"android:textColor="@android:color/black"android:textSize="16sp" /><!-- 描述詳情區域 --><TextView android:id="@+id/app_detail_des_tv_des"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="5dp"android:text="內容"android:textColor="@android:color/darker_gray"android:textSize="14sp" /><!-- 作者區域 --><RelativeLayout android:layout_width="match_parent"android:layout_height="25dp" ><TextView android:id="@+id/app_detail_des_tv_author"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerVertical="true"android:text="作者 : "android:textColor="@android:color/darker_gray"android:textSize="14sp" /><ImageView android:id="@+id/app_detail_des_iv_arrow"android:layout_width="15dp"android:layout_height="15dp"android:layout_alignParentRight="true"android:layout_centerVertical="true"android:src="@drawable/arrow_down" /></RelativeLayout></LinearLayout></FrameLayout> public class AppDetailDesHolder extends BaseHolder<AppInfoBean> implements OnClickListener {@ViewInject(R.id.app_detail_des_tv_author)TextView mTvAuthor;@ViewInject(R.id.app_detail_des_iv_arrow)ImageView mIvArrow;@ViewInject(R.id.app_detail_des_tv_des)TextView mTvDes;private boolean isOpen = true;private int mTvDesMeasuredHeight;private AppInfoBean mData;@Overridepublic View initHolderView() {View view = View.inflate(UIUtils.getContext(), R.layout.item_app_detail_des, null);ViewUtils.inject(this, view);view.setOnClickListener(this);return view;}@Overridepublic void refreshHolderView(AppInfoBean data) {mData = data;mTvAuthor.setText(data.author);mTvDes.setText(data.des);mTvDes.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {@Overridepublic void onGlobalLayout() {mTvDesMeasuredHeight = mTvDes.getMeasuredHeight();// 默認折疊toggle(false);// 如果不移除,一會高度變成7行的時候.mTvDesMeasuredHeight就會變mTvDes.getViewTreeObserver().removeGlobalOnLayoutListener(this);}});}@Overridepublic void onClick(View v) {toggle(true);}private void toggle(boolean isAnimation) {if (isOpen) {// 折疊/**mTvDes高度發生改變應有的高度-->7行的高度*/int start = mTvDesMeasuredHeight;int end = getShortHeight(7, mData);if (isAnimation) {doAnimation(start, end);} else {mTvDes.setHeight(end);}} else {// 展開int start = getShortHeight(7, mData);int end = mTvDesMeasuredHeight;if (isAnimation) {doAnimation(start, end);} else {mTvDes.setHeight(end);}}if (isAnimation) {// mTvDes正在折疊或者展開if (isOpen) {ObjectAnimator.ofFloat(mIvArrow, "rotation", 180, 0).start();} else {ObjectAnimator.ofFloat(mIvArrow, "rotation", 0, 180).start();}}isOpen = !isOpen;}public void doAnimation(int start, int end) {ObjectAnimator animator = ObjectAnimator.ofInt(mTvDes, "height", start, end);animator.start();animator.addListener(new AnimatorListener() {@Overridepublic void onAnimationStart(Animator arg0) {// 動畫開始}@Overridepublic void onAnimationRepeat(Animator arg0) {// 動畫重復}@Overridepublic void onAnimationEnd(Animator arg0) {// 動畫結束ViewParent parent = mTvDes.getParent();while (true) {parent = parent.getParent();if (parent == null) {// 已經沒有父親break;}if (parent instanceof ScrollView) {// 已經找到((ScrollView) parent).fullScroll(View.FOCUS_DOWN);break;}}}@Overridepublic void onAnimationCancel(Animator arg0) {// 動畫取消}});}/*** @param i 指定行高* @param data 指定textView的內容* @return*/private int getShortHeight(int i, AppInfoBean data) {//臨時textView,只做測繪用TextView tempTextView = new TextView(UIUtils.getContext());tempTextView.setLines(7);tempTextView.setText(data.des);tempTextView.measure(0, 0);int measuredHeight = tempTextView.getMeasuredHeight();return measuredHeight;}}

總結

以上是生活随笔為你收集整理的属性动画的应用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。