android实习程序3
来源:互联网 发布:淘宝有人恶意下单付款 编辑:程序博客网 时间:2024/06/15 00:20
排序(选择 冒泡 插入 快速)
面对对象
static final
构造方法
继承 (方法重写重载,构造方法不能继承)
抽象 接口 super this
匿名内部类
collection
list (有次序): arraylist vector
set (没有次序) : Hashset
Map : Hashtable HashSet ()
JAVA基本掌握知识
JAVAIO流
多线程 (线程同步 加锁)
Sockect编程
1、时间的显示(date\Time)
2、改变图片的透明度、与浏览?
3、进度条
4、利用进度条和星级改变图片的透明度
===========================
1、时间的显示
.java
package com.tarena.day03;
import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.TimePicker;
import android.widget.Toast;
public class Day03_02Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
DatePicker date =(DatePicker) findViewById(R.id.datePicker1);
TimePicker time = (TimePicker)findViewById(R.id.timePicker1);
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int monthOfYear = cal.get(Calendar.MONTH)+2;
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
date.init(year, monthOfYear, dayOfMonth, new OnDateChangedListener(){
@Override
public void onDateChanged(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
Toast.makeText(Day03_02Activity.this, "选择时间是:"+year+"年"+monthOfYear+"月"+dayOfMonth+"日", 3000).show();
}
});
time.setOnTimeChangedListener(new OnTimeChangedListener(){
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub
Toast.makeText(Day03_02Activity.this, "当前时间为:"+hourOfDay+"时"+minute+"分", 1000).show();
}
});
}
}
.main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity= "center_horizontal"
>
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
效果为点击某一时间天,会在下方显示时间
好像有问题,月份不对。。。。。。。
=================================
2、改变图片的透明度、与浏览
.java
package com.tarena.day03;
import android.app.Activity;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class Day03_01Activity extends Activity {
Button plus,minus,next;
ImageView img;
int alpha = 255;
int[] imgs = {R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
int curInt = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_toumingdu);
//初始化组件
plus = (Button)findViewById(R.id.plus);
minus = (Button)findViewById(R.id.minus);
next = (Button)findViewById(R.id.next);
img = (ImageView)findViewById(R.id.img);
//按next钮添加事件监听
next.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
curInt++;
if(curInt>=imgs.length){
curInt = imgs.length-1;
Toast.makeText(Day03_01Activity.this, "已经是最后一张图片了", 3000).show();
}
BitmapDrawable dra = (BitmapDrawable)img.getDrawable();
//判断是否回收了之前的图片
if(!dra.getBitmap().isRecycled()){
//把图片回收
dra.getBitmap().recycle();
}
//设置新的图片
img.setImageBitmap(BitmapFactory.decodeResource(getResources(), imgs[curInt]));
}
});
plus.setOnClickListener(new MyClick());
minus.setOnClickListener(new MyClick());
}
class MyClick implements OnClickListener{
public void onClick(View v) {
if(v==plus){
alpha+=20;
}else if(v==minus){
alpha-=20;
}
if(alpha<=0){
alpha=0;
}
if(alpha>=255){
alpha=255;
}
// /设置图片的透明度
img.setAlpha(alpha);
}
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="增大透明度"
android:id="@+id/plus"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="缩小透明度"
android:id="@+id/minus"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一张"
android:id="@+id/next"
/>
</LinearLayout>
<ImageView
android:layout_width="fill_parent"
android:layout_height="400px"
android:scaleType="fitCenter"
android:src="@drawable/a"
android:id="@+id/img"
/>
</LinearLayout>
=================================
3、进度条
.java
package com.tarena.day03;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
public class processbar extends Activity {
int status=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_jindutiao);
final ProgressBar bar=(ProgressBar)findViewById(R.id.bar);
final Handler h=new Handler(){
@Override
public void handleMessage(Message msg) {
if(msg.what==0x1122){
bar.setProgress(status);
}
}
};
new Thread(){
public void run(){
while(status<=100){
status++;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Message msg=new Message();
msg.what=0x1122;
h.sendMessage(msg);
}
}
}.start();
}
}
.main
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/bar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:max="100"
/>
</RelativeLayout>
效果为进度的增加
==================================
4、利用进度条和星级改变图片的透明度
.java
package com.tarena.day03;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
public class SeekBarActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SeekBar bar = (SeekBar)findViewById(R.id.seekBar1);
final ImageView img = (ImageView)findViewById(R.id.img);
RatingBar rbar = (RatingBar)findViewById(R.id.ratingBar1);
//对bar添加事件监听
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
}
public void onStartTrackingTouch(SeekBar seekBar) {
}
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
//根据进度条设置透明度
img.setAlpha(progress);
}
});
//对ratingbar添加事件监听
rbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener(){
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
//根据进度条设置透明度
img.setAlpha((int)(255/5*rating));
}
});
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="400dip"
android:src="@drawable/a"
android:scaleType="fitCenter"
android:id="@+id/img"
/>
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="255"
android:progress="50"
/>
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.5"
android:max="255"
android:progress="50"
/>
</LinearLayout>
实现的效果为:
- android实习程序3
- android实习程序
- android实习程序2
- 实习程序3
- android实习程序 ——短信
- android实习程序4——页面跳转
- android实习程序6——拨号通话
- android实习程序7——通话记录显示
- 实习程序收藏
- 编程实习程序
- 实习程序1
- 实习程序2
- 实习程序4
- 实习程序5
- 实习程序6
- 生产实习(Android)一
- 生产实习(Android)二
- 生产实习(Android)三
- 20-获得系统当前时间的字符串格式(字符串处理)
- enq:SQ contention / row cache lock / DFS lock handle(SV) 等待事件 说明
- IOS设计模式学习(15)访问者
- hdwiki 5.0漏洞修复(补充中。。)
- Set接口
- android实习程序3
- 多线程线程间通信
- 最激励人心\作为一个程序员
- Linux机器系统时间out of range
- Linux 下zip包的压缩与解压
- 机器学习算法与中国文化
- eas 中由 ssl.c 文件中 SSL_close_all 引发的 bug
- 给程序员新手的一些建议
- (Python学习1) Python对象初探