谷歌电子市场第4天总结
生活随笔
收集整理的這篇文章主要介紹了
谷歌电子市场第4天总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一.值動畫展開線性布局
點擊內容顯示隱藏內容
/**安全Holder設置動畫效果*/ public class DetailSafeHolder extends BaseHolder<Appinfo> implementsOnClickListener {@ViewInject(R.id.safe_layout)private RelativeLayout safe_layout;@ViewInject(R.id.safe_content)private LinearLayout safe_content;@ViewInject(R.id.safe_arrow)private ImageView safe_arrow;ImageView[] ivs;ImageView[] iv_des;TextView[] tv_des;LinearLayout[] des_layout;@Overrideprotected View initView() {View view = View.inflate(BaseApplication.getApplication(),R.layout.detail_safe, null);ViewUtils.inject(this, view);ivs = new ImageView[4]; // 初始化標題欄的圖片ivs[0] = (ImageView) view.findViewById(R.id.iv_1);ivs[1] = (ImageView) view.findViewById(R.id.iv_2);ivs[2] = (ImageView) view.findViewById(R.id.iv_3);ivs[3] = (ImageView) view.findViewById(R.id.iv_4);iv_des = new ImageView[4]; // 初始化每個條目描述的圖片iv_des[0] = (ImageView) view.findViewById(R.id.des_iv_1);iv_des[1] = (ImageView) view.findViewById(R.id.des_iv_2);iv_des[2] = (ImageView) view.findViewById(R.id.des_iv_3);iv_des[3] = (ImageView) view.findViewById(R.id.des_iv_4);tv_des = new TextView[4]; // 初始化每個條目描述的文本tv_des[0] = (TextView) view.findViewById(R.id.des_tv_1);tv_des[1] = (TextView) view.findViewById(R.id.des_tv_2);tv_des[2] = (TextView) view.findViewById(R.id.des_tv_3);tv_des[3] = (TextView) view.findViewById(R.id.des_tv_4);des_layout = new LinearLayout[4]; // 初始化條目線性布局des_layout[0] = (LinearLayout) view.findViewById(R.id.des_layout_1);des_layout[1] = (LinearLayout) view.findViewById(R.id.des_layout_2);des_layout[2] = (LinearLayout) view.findViewById(R.id.des_layout_3);des_layout[3] = (LinearLayout) view.findViewById(R.id.des_layout_4);safe_layout.setOnClickListener(this);//默認初始化不顯示RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) safe_content.getLayoutParams();params.height = 0;safe_content.setLayoutParams(params);return view;}@Overrideprotected void refreshView(Appinfo data) {List<String> safeUrl = data.getSafeUrl();//大圖片urlList<String> safeDesUrl = data.getSafeDesUrl();//小圖片urlList<String> safeDes = data.getSafeDes();//描述List<Integer> safeDesColor = data.getSafeDesColor(); // 文字顏色0 1 2 3// 如果個數item或者其中一個少于4個,就將多的那個隱藏for (int i = 0; i < 4; i++) {if (i < safeUrl.size() && i < safeDesUrl.size()&& i < safeDes.size() && i < safeDesColor.size()) {ivs[i].setVisibility(View.VISIBLE);des_layout[i].setVisibility(View.VISIBLE);//設置圖片和描述BitmapHelper.getBitmapUtils().display(ivs[i],FileUtils.URL + "image?name=" + safeUrl.get(i));BitmapHelper.getBitmapUtils().display(iv_des[i],FileUtils.URL + "image?name=" + safeDesUrl.get(i));tv_des[i].setText(safeDes.get(i));// 根據返回的顏色類型設置不同的顏色int color;int colorType = safeDesColor.get(i);if (colorType >= 1 && colorType <= 3) {color = Color.rgb(255, 153, 0); // 00 00 00} else if (colorType == 4) {color = Color.rgb(0, 177, 62);} else {color = Color.rgb(122, 122, 122);}tv_des[i].setTextColor(color);} else {ivs[i].setVisibility(View.GONE);des_layout[i].setVisibility(View.GONE);}}}boolean flag ;// 默認關閉int startHeight;int endHeight;@Overridepublic void onClick(View v) {if (!flag) {// 如果是關閉,點擊就打開flag = true;// safe_content.setVisibility(View.GONE);startHeight = 0;endHeight = getMeasureHeight();} else { // 否則就關閉flag = false;startHeight = getMeasureHeight();endHeight = 0;// safe_content.setVisibility(View.VISIBLE);}//設置值動畫,變化final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) safe_content.getLayoutParams();ValueAnimator animator = ValueAnimator.ofInt(startHeight,endHeight); <span style="white-space:pre"> </span>//監聽動畫的變化 animation.getAnimatedValue在一定時間內容按照 startHeight —>endHeight 變化animator.addUpdateListener(new AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator animation) {params.height = (Integer) animation.getAnimatedValue();safe_content.setLayoutParams(params);}});animator.setDuration(400);animator.start();//動畫的監聽animator.addListener(new AnimatorListener() {@Overridepublic void onAnimationStart(Animator animation) {}@Overridepublic void onAnimationRepeat(Animator animation) {}//動畫完之后改變箭頭@Overridepublic void onAnimationEnd(Animator animation) {if(flag){safe_arrow.setImageResource(R.drawable.arrow_up);}else{safe_arrow.setImageResource(R.drawable.arrow_down);}}@Overridepublic void onAnimationCancel(Animator animation) {}});}//獲取控件safe_layout的測量的高public int getMeasureHeight() {int width = safe_content.getMeasuredHeight();// 寬是和匹配父窗體的,不變int widthMeasureSpec = MeasureSpec.makeMeasureSpec(width,MeasureSpec.EXACTLY);//寬度精確int heightMeasureSpec = MeasureSpec.makeMeasureSpec(1000,MeasureSpec.AT_MOST);//高度設置合適的值,1000//自定義該線性布局的規則safe_content.measure(widthMeasureSpec, heightMeasureSpec); <span style="white-space:pre"> </span>//safe_content.measure(0,0);return safe_content.getMeasuredHeight();} }
二.再來一次.動畫
public class DetailDesHolder extends BaseHolder<Appinfo> implementsOnClickListener {@ViewInject(R.id.des_content)private TextView des_content;@ViewInject(R.id.des_author)private TextView des_author;@ViewInject(R.id.des_arrow)private ImageView des_arrow;@ViewInject(R.id.des_layout)private RelativeLayout des_layout;@Overrideprotected View initView() {View view = View.inflate(BaseApplication.getApplication(),R.layout.detail_des, null);ViewUtils.inject(this, view);return view;}@Overrideprotected void refreshView(Appinfo data) {scrollView = getScrollView(des_content);des_content.setText(data.getDes());des_author.setText("作者:" + data.getAuthor());// 默認設置的高度顯示7行RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) des_content.getLayoutParams();layoutParams.height = getShortHeight();des_content.setLayoutParams(layoutParams);// 默認設置的箭頭des_arrow.setImageResource(R.drawable.arrow_down);des_layout.setOnClickListener(this);}//獲取ScrollViewprivate ScrollView getScrollView(View view) {ViewParent parent = view.getParent();if(parent instanceof ViewGroup){ViewGroup group = (ViewGroup)parent;if(group instanceof ScrollView){return (ScrollView)group;}else{return getScrollView(group);}}else{return null;}}boolean flag = false;private ScrollView scrollView;@Overridepublic void onClick(View v) {int startHeight;int endHeight;if(!flag){flag = true;startHeight = getShortHeight();endHeight = getLongHeight();}else{flag = false;startHeight = getLongHeight();endHeight = getShortHeight();}/**值動畫從startHeight--> endHeight*/final ValueAnimator animator = ValueAnimator.ofInt(startHeight,endHeight);animator.addUpdateListener(new AnimatorUpdateListener() {@Overridepublic void onAnimationUpdate(ValueAnimator arg0) {// TODO Auto-generated method stubint animatedValue = (Integer) animator.getAnimatedValue();RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) des_content.getLayoutParams();layoutParams.height = animatedValue;des_content.setLayoutParams(layoutParams);scrollView.scrollTo(0, scrollView.getMeasuredHeight());//滑動到低端}});animator.setDuration(500);animator.start();//監聽動畫完成后的事件,實現箭頭的變化animator.addListener(new AnimatorListener() {@Overridepublic void onAnimationStart(Animator arg0) {}@Overridepublic void onAnimationRepeat(Animator arg0) {}@Overridepublic void onAnimationEnd(Animator arg0) {if(flag){des_arrow.setImageResource(R.drawable.arrow_up);}else{des_arrow.setImageResource(R.drawable.arrow_down);}}@Overridepublic void onAnimationCancel(Animator arg0) {}});}// 獲得顯示7行的的高度public int getShortHeight() {TextView textView = new TextView(BaseApplication.getApplication());textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);// 設置字體大小14dptextView.setMaxLines(7);textView.setLines(7);// 管你有多少行,都必須顯示7行// int width = des_content.getMeasuredWidth();textView.measure(0, 0);//通知測量int measuredHeight = textView.getMeasuredHeight();return measuredHeight;}// 獲得整個高度public int getLongHeight() {int width = des_content.getMeasuredWidth();int widthMeasureSpec = MeasureSpec.makeMeasureSpec(width,MeasureSpec.EXACTLY);// 以實際測量為標準int heightMeasureSpec = MeasureSpec.makeMeasureSpec(1000,MeasureSpec.AT_MOST);// 最大標準,為1000des_content.measure(widthMeasureSpec, heightMeasureSpec);int measuredHeight = des_content.getMeasuredHeight();System.out.println("long" + measuredHeight);return measuredHeight;} }
總結
以上是生活随笔為你收集整理的谷歌电子市场第4天总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 稚晖君教你制作全球最迷你的自平衡机器人
- 下一篇: fckeditor java 使用方法_