編輯:關於Android編程
public class ScrollBanner extends LinearLayout {
private TextView mBannerTV1;
private TextView mBannerTV2;
private Handler handler;
private boolean isShow;
private int startY1, endY1, startY2, endY2;
private Runnable runnable;
private List list;
private int position = 0;
private int offsetY = 100;
public ScrollBanner(Context context) {
this(context, null);
}
public ScrollBanner(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ScrollBanner(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
View view = LayoutInflater.from(context).inflate(R.layout.view_scroll_banner, this);
mBannerTV1 = (TextView) view.findViewById(R.id.tv_banner1);
mBannerTV2 = (TextView) view.findViewById(R.id.tv_banner2);
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
isShow = !isShow;
if (position == list.size())
position = 0;
if (isShow) {
mBannerTV1.setText(list.get(position++));
} else {
mBannerTV2.setText(list.get(position++));
}
startY1 = isShow ? 0 : offsetY;
endY1 = isShow ? -offsetY : 0;
ObjectAnimator.ofFloat(mBannerTV1, "translationY", startY1, endY1).setDuration(300).start();
startY2 = isShow ? offsetY : 0;
endY2 = isShow ? 0 : -offsetY;
ObjectAnimator.ofFloat(mBannerTV2, "translationY", startY2, endY2).setDuration(300).start();
handler.postDelayed(runnable, 3000);
}
};
}
public List getList() {
return list;
}
public void setList(List list) {
this.list = list;
}
public void startScroll() {
handler.post(runnable);
}
public void stopScroll() {
handler.removeCallbacks(runnable);
}
}
view_scroll_banner.xml
使用方法
scrollBanner.setList(list);
scrollBanner.startScroll();
OptionsMenu(選項菜單)1.重寫Activity的onCreateOptionsMenu(Menu menu)方法,在該方法裡調用Menu對象的方法來添加菜單項
1 Android控件架構1 簡單的總結(1)父View優先攔截當前事件,攔截不成功就讓子View對當前事件進行攔截。(2)如果攔截成功的話,就會沿著子view到父Vie
本文實例講述了Android控件之TabHost用法。分享給大家供大家參考。具體如下:以下通過TabHost實現android選項卡。main.xml布局文件:<&
1. 在IDE中查看Log信息 當程序運行垃圾回收的時候,會打印一條Log信息,其格式如下: D/dalvikvm: , , , GC_Reason表