Android记事本
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1.只是在主程序里面添加此代码:
TextView textView = new TextView(this);
textView.setText("你好啊");
setContentView(textView);
就会在Android虚拟机上显示“你好啊”
2.只在Main.xml里面添加代码:
<TextView
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();
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);
tv.setText(style);
7.
8.
@动画,是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的代码
<declare-styleable name="Gallery">
<attr name="android:galleryItemBackground"/>
</declare-styleable>
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 = new ScaleAnimation(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
TabHost添加背景图片
tabHost.addTab(tabHost.newTabSpec("Second").setIndica tor("Second",getResources().getDrawable(android.R.dra wable.alert_dark_frame)));
用Timer获取系统的时间
;
;
@Override
publicint onStartCommand(Intent intent, int flags, int startId) {
timer = new Timer();
task = new TimerTask() {
@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);
}。