1.代码中加动态添加TextView及布局
if(tradeRecommenResult!=null&&tradeRecommenResult.getData()!=null&&!tradeRecommenResult.getData().isEmpty()){ ArrayList<String> lists = new ArrayList<>(); for (int i = 0; i < tradeRecommenResult.getData().size(); i++) { lists.add(tradeRecommenResult.getData().get(i).time+" "+tradeRecommenResult.getData().get(i).info); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT ); TextView mTextView = new TextView(getActivity()); String result = i==1?" ":""; mTextView.setText(result+tradeRecommenResult.getData().get(i).time+" "+tradeRecommenResult.getData().get(i).info); mTextView.setTextColor(Color.parseColor("#A2BBF6")); mTextView.setTextSize(12); mLinearLayout.addView(mTextView,p); mTranslateAnimation = new TranslateAnimation(0, -mLinearLayout.getMeasuredWidth(), 0, 0); mTranslateAnimation.setRepeatCount(Animation.INFINITE); //mTranslateAnimation.setInterpolator(new LinearInterpolator()); mTranslateAnimation.setDuration(20000); mLinearLayout.startAnimation(mTranslateAnimation);
}
2.
TranslateAnimation
setInterpolator(new LinearInterpolator())
3.horizontionscrollview禁止滑动
mHorizontalScrollView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; }
});
3.属性动画
后,补间动画还有一个致命的缺陷,就是它只是改变了View的显示效果而已,而不会真正去改变View的属性。什么意思呢?比如说,现在屏幕的左上角有一个按钮,然后我们通过补间动画将它移动到了屏幕的右下角,现在你可以去尝试点击一下这个按钮,点击事件是绝对不会触发的,因为实际上这个按钮还是停留在屏幕的左上角,只不过补间动画将这个按钮绘制到了屏幕的右下角而已。
4.
getMeasuredWidth及getWidth
final int width = mLinearLayout.getWidth(); animator = ObjectAnimator.ofFloat(mLinearLayout, "translationX", 0, -width+300); animator.setRepeatCount(ValueAnimator.INFINITE); animator.setInterpolator(new LinearInterpolator()); animator.setDuration(10000); animator.start();
刚开始width为0
通过post可以将一个runnable投递到消息队列的尾部,然后等待Looper调用runnable的时候,View也已经初始化好了,代码如下:
mLinearLayout.post(new Runnable() { @Override public void run() { final int width = mLinearLayout.getWidth(); animator = ObjectAnimator.ofFloat(mLinearLayout, "translationX", 0, -width); animator.setRepeatCount(ValueAnimator.INFINITE); animator.setInterpolator(new LinearInterpolator()); animator.setDuration(10000); animator.start(); } });
5.@SerializedName(value = "status",alternate = {"code","errorCode"})
情况一:多个字段取一个
项目中只用了一个字段来更改解析字段名,还有一种情况,我们在开发的时候会用到,这里举一个不太合适的例子,例如:后台同学给配数据,后期要废弃其中一个字段,但又不能影响老版本的使用,于是增加了一个字段,取值相同。
解决:
当然我们在新版本直接讲字段改成新数据字段取值就好了。
这是一种解决办法,但是不能保证以后没有其它字段废弃或者添加,这里在介绍一个属性 alternate 简明知意,用来替换;
可以这么写:
@SerializedName(value = "thumburl", alternate = {"thumburl_new"})
http://blog.csdn.net/cpfdpzc/article/details/53349008