当前位置: 编程技术>移动开发
本页文章导读:
▪TextView 跑马灯成效 TextView 跑马灯效果
package ddd.testdd.com;
1、重新封装了TextView
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class AlwaysMarqueeTextView extends TextView {
pub.........
▪ 异步加载进度展示 异步加载进度显示
package com.rcsit.android.mas.email.dialog;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.As.........
▪ 更新button下的数字 更新button上的数字
public class CounterButton extends Button{
protected int count=0;
protected final Paint myTextPaint = new Paint();
protected final Paint myCirclePaint = new Paint();
public Cou.........
[1]TextView 跑马灯成效
来源: 互联网 发布时间: 2014-02-18
TextView 跑马灯效果
package ddd.testdd.com;
1、重新封装了TextView
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class AlwaysMarqueeTextView extends TextView {
public AlwaysMarqueeTextView(Context context) {
super(context);
}
public AlwaysMarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean isFocused() {
return true;
}
}
2 在xml中调用
<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ddd.testdd.com.alwaysmarqueetextview
android:text="哈哈我的跑马灯程序接下来是歌词呵呵:沉鱼落雁,闭月羞花"
android:focusableintouchmode="true" android:scrollhorizontally="true"
android:marqueerepeatlimit="marquee_forever" android:singleline="true"
android:focusable="true" android:ellipsize="marquee"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:gravity="center|clip_horizontal"/>
</linearlayout>
1 楼
shadow88
2011-08-20
这个方法是不错,但是如果是由多个组件组合,只有这个获得了焦点,那么其他的事件都不能用了,比如说:我写了个listView,在list item里有textview(跑马灯)还有imageview以及我要点击这个list item进入下一个activity 怎么办呢
[2] 异步加载进度展示
来源: 互联网 发布时间: 2014-02-18
异步加载进度显示
package com.rcsit.android.mas.email.dialog; import android.app.Activity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.os.AsyncTask; import android.widget.Toast; /** * 异步加载类 * * @author wanglin(lin3.wang@changhong.com) * 2011-5-20下午04:01:02 */ public abstract class LoadingDialog<Input, Result> extends AsyncTask<Input, WSError, Result> { private ProgressDialog mProgressDialog; protected Activity mActivity; private int mLoadingMsg; private int mFailMsg; private boolean mEnddismiss = true; public LoadingDialog(Activity activity, int loadingMsg, int failMsg) { this.mActivity = activity; this.mLoadingMsg = loadingMsg; this.mFailMsg = failMsg; } public LoadingDialog(Activity activity, int loadingMsg, int failMsg, boolean Enddismiss) { this.mActivity = activity; this.mLoadingMsg = loadingMsg; this.mFailMsg = failMsg; this.mEnddismiss = Enddismiss; } /** * 用户调用取消时,要做的操作 */ @Override public void onCancelled() { failMsg(); super.onCancelled(); } @Override public void onPreExecute() { String title = ""; String message = mActivity.getString(mLoadingMsg); mProgressDialog = ProgressDialog.show(mActivity, title, message, true, true, new OnCancelListener() { public void onCancel(DialogInterface dialogInterface) { LoadingDialog.this.cancel(true); } }); super.onPreExecute(); } /** * 后台执行,比较耗时的操作都可以放在这里。注意这里不能直接操作UI。 */ @Override public abstract Result doInBackground(Input... params); /** * 相当于Handler 处理UI的方式 */ @Override public void onPostExecute(Result result) { super.onPostExecute(result); if (!this.mEnddismiss) mProgressDialog.dismiss(); if (result != null) { doStuffWithResult(result); } else { failMsg(); } if (this.mEnddismiss) mProgressDialog.dismiss(); } protected void failMsg() { Toast.makeText(mActivity, mFailMsg, 2000).show(); } /** * Very abstract function hopefully very meaningful name, executed when * result is other than null * * @param result * @return */ public abstract void doStuffWithResult(Result result); /** * 使用进度条增加用户体验度 */ @Override protected void onProgressUpdate(WSError... values) { Toast.makeText(mActivity, values[0].getMessage(), Toast.LENGTH_LONG) .show(); this.cancel(true); mProgressDialog.dismiss(); super.onProgressUpdate(values); } }
[3] 更新button下的数字
来源: 互联网 发布时间: 2014-02-18
更新button上的数字
public class CounterButton extends Button{ protected int count=0; protected final Paint myTextPaint = new Paint(); protected final Paint myCirclePaint = new Paint(); public CounterButton(Context context, AttributeSet attrs) { super(context, attrs); this.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.ic_dialog_email)); this.myCirclePaint.setARGB(150, 255, 0, 0); this.myTextPaint.setARGB(150, 255, 255, 255); } @Override protected void onDraw(Canvas canvas) { if(count!=0){ canvas.drawCircle((float) (this.getWidth()*.75), (float) (this.getHeight()*.4), this.getHeight()/5, myCirclePaint); canvas.drawText(Integer.toString(count), (float) (this.getWidth()*.75), (float) (this.getHeight()*.4), this.myTextPaint); } } }
CounterButton cb=(CounterButton) findViewById(R.id.whateverYouGaveItInXML); cb.count=SomeNewNumber; cb.invalidate;
最新技术文章: