android:layout_width=\"fill_parent\" android:layout_height=\"wrap_content\" android:text=\"你好\" />3.
4.设置超链接:android:autoLink=”all”
5.跑马灯:android:singleLine=”true”把所以要跑马灯的都显示成一行
android:focusable=\"true\" android:ellipsize=\"marquee\"
android:marqueeRepeatLimit=\"marquee_forever\" android:focusableInTouchMode=\"true\"
6.设置字体颜色:
TextView tv = (TextView) findViewById(R.id.tv);
String str = \"欢迎大家收看《Android开发从零开始》系列课程,感谢大家的支持。\";
SpannableStringBuilder style = new SpannableStringBuilder(str); style.setSpan(new ForegroundColorSpan(Color.RED), 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new ForegroundColorSpan(Color.GREEN), 6, 21, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
style.setSpan(new ForegroundColorSpan(Color.BLUE), 21, 26, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
7. 8. tv.setText(style);
private AlphaAnimation an1 = new AlphaAnimation(1, 0);定义他的@动画,是android
自带的
an1.setDuration(1000);休息的时间问1000毫秒
imgv1.startAnimation(an1);// startAnimation 启动动画
9.给自己的界面设置空间大小 Android:layout_weight=”X”
10.实现图片的循环
a先取得getContext的返回最大值 Public int getContext(){
Return Integer.MAX_VALUE; }
b有就是设置图片给ImageView对象
Imageview.setImageResource(resides[position%resIds.length]);
c.我们还可以给图片添加一个边框 首先定义一个int mGalleryItemBackground;,然后取得Gallery属性的Index id的值 public ImageAdapter(Context c) { mContext = c;
}
// 使用在res/value/attrs.xml中的Gallery属性
TypedArray a = obtainStyledAttributes(R.styleable.Gallery); // 取得Gallery属性的Index id
mGalleryItemBackground = a.getResourceId( R.styleable.Gallery_android_galleryItemBackground, 0); // 让对象的styleable属性能够反复使用 a.recycle();
在res/value/attrs.xml的代码
11.AlertDialog的使用
AlertDialog.Builder builder = new AlertDialog.Builder( C018_onDoubleClickActivity.this); builder.setTitle(\"双击\");
builder.setMessage(\"Very Good\"); builder.show();
图片的淡进淡出:AlphaAnimation
aa = new AlphaAnimation(1, 0);// 1, 0从透明到不透明
图片的移动:TranslateAnimation
ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); ta.setDuration(3000); //显示的时间 startAnimation(al);//启动
startAnimation(ta);
图片的旋转:RotateAnimation
ra = new RotateAnimation(0, 720, Animation.RELATIVE_TO_PARENT, 0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
图片的伸缩:ScaleAnimation
sa = newScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
帧动画
Alpha渐变效果共同属性
fromX, toX, fromY, toY, pivotXType, pivotXValue, pivotYType, pivotYValue
Canvas图形的绘制 方法 drawRect drawCircle drawOval drawLine drawPoint 说明 绘制矩形 绘制圆形(STROKE空心)(FILL实心) 绘制椭圆 绘制直线 绘制点
TabHost添加背景图片
tabHost.addTab(tabHost.newTabSpec(\"Second\").setIndicator(\"Second\",getResources().getDrawable(android.R.drawable.alert_dark_frame)));
用Timer获取系统的时间
privateTimertimer; privateTimerTasktask;
@Override publicint onStartCommand(Intent intent, int flags, int startId) {
timer = new Timer(); task = newTimerTask() {
@Override
publicvoid run() {
Calendar c = Calendar.getInstance();
String time = c.get(Calendar.HOUR_OF_DAY) + \":\" + c.get(Calendar.MINUTE) + \":\" + c.get(Calendar.SECOND);
System.out.println(time); } };
timer.schedule(task, 1000, 1000);
returnsuper.onStartCommand(intent, flags, startId); }