当前位置:  编程技术>移动开发
本页文章导读:
    ▪erlang 下令编译.erl文件        erlang 命令编译.erl文件 在home/blue新建文件夹:erl 1: 此时可以编译这个文件夹下的文件了。 首先:输入 ~$erl cd("/home/blue/erl"). c(demo).   2: ~$cd /home/blue/erl $erl c(demo). ......
    ▪ 【so easy~】 底部菜单可挪动焦点~(仿网易新闻等应用)        【so easy~】 底部菜单可移动焦点~!(仿网易新闻等应用) 最近比较懒惰,也没有更新博客。今天就把刚刚实现的一个小效果分享给大家! http://androiddada.iteye.com/ 我的底部菜单是使用ActivityGroup实.........
    ▪ 多线程上载文件       多线程下载文件 (1)public class MultiThreadDownload extends Thread {    //定义的一些常量变量,看名字就知道什么意思了private static final int BUFFER_SIZE = 1024;private int blockSize;private int threadNum = 5;priva.........

[1]erlang 下令编译.erl文件
    来源: 互联网  发布时间: 2014-02-18
erlang 命令编译.erl文件

在home/blue新建文件夹:erl

1:

此时可以编译这个文件夹下的文件了。

首先:输入

~$erl

cd("/home/blue/erl").

c(demo).

 

2:

~$cd /home/blue/erl

$erl

c(demo).


    
[2] 【so easy~】 底部菜单可挪动焦点~(仿网易新闻等应用)
    来源: 互联网  发布时间: 2014-02-18
【so easy~】 底部菜单可移动焦点~!(仿网易新闻等应用)

最近比较懒惰,也没有更新博客。今天就把刚刚实现的一个小效果分享给大家!

http://androiddada.iteye.com/

我的底部菜单是使用ActivityGroup实现的,先上代码,ActivityGroup布局:


 

<?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"
    >

    <!-- 动态显示界面 -->
    <LinearLayout
        android:id="@+id/bodyL"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    </LinearLayout>

    <!-- 底部功能菜单栏  -->
    <LinearLayout 
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent"
        android:layout_height="60px"
        android:orientation="horizontal" >

        <LinearLayout
            android:id="@+id/home"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="5"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:background="@drawable/tab_background" >

            <ImageView
                android:layout_width="32dp"
                android:layout_height="35dp"
                android:layout_gravity="top|center"
                android:layout_marginTop="4dp"
                android:background="@drawable/home" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/gamebox"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="5"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:background="@drawable/tab_background"  >

            <ImageView
                android:layout_width="32dp"
                android:layout_height="35dp"
                android:layout_gravity="top|center"
                android:layout_marginTop="4dp"
                android:background="@drawable/gamebox" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/team"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="5"
            android:gravity="center_horizontal"
            android:orientation="vertical"
            android:background="@drawable/tab_background"  >

            <ImageView
                android:layout_width="32dp"
                android:layout_height="35dp"
                android:layout_gravity="top|center"
                android:layout_marginTop="4dp"
                android:background="@drawable/team" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/more"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_weight="5"
            android:gravity="center_horizontal"
            android:orientation="vertical" 
            android:background="@drawable/tab_background" >

            <ImageView
                android:layout_width="32dp"
                android:layout_height="35dp"
                android:layout_gravity="top|center"
                android:layout_marginTop="4dp"
                android:background="@drawable/more" />

        </LinearLayout>
    </LinearLayout>
    <!-- 底部焦点 使用Imageview 注意要放在RelativeLayout最后 才可遮挡后面的菜单 建议使用半透明图片  -->
    <ImageView android:layout_alignParentBottom="true" android:id="@+id/tab_selector" android:layout_width="wrap_content" android:layout_height="60px" android:src="/blog_article/@drawable/tab_highlight/index.html"/>

</RelativeLayout>




 ActivityGroup 代码:

 

public class ActsGroup extends ActivityGroup {
	private DisplayMetrics _dm = null; // 获得分辨率
	private ImageView _tab_selector = null; //焦点控件
	private LinearLayout bodyView;
	private LinearLayout home, gamebox, team, more;
	private int flag = 0; // 通过标记跳转不同的页面,显示不同的菜单项
	private int temp_flag = 0;
//	private String parameter = Constant.BUTTON_HOME;// 初始化加载

	public ActsGroup(){
		_dm = new DisplayMetrics();
	}
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE); //无标题
		super.onCreate(savedInstanceState);
		setContentView(R.layout.acts_group);
		suitScreen();
		initMainView();
		// 主界面开始接收参数
		Bundle bundle = getIntent().getExtras();
		if (null != bundle) {
			flag = bundle.getInt("flag");
		}
		// 默认显示 播放界面
		showView(flag);

		home.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				flag = 0;
				showView(flag);
			
			}
		});
		gamebox.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				flag = 1;
				showView(flag);

			}
		});
		team.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				flag = 2;
				showView(flag);
			
			}
		});
		more.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				flag = 3;
				showView(flag);
				

			}
		});

	}
	
	/*
	 * 初始化主界面底部的功能菜单
	 */
	public void initMainView() {
		bodyView = (LinearLayout) findViewById(R.id.bodyL);
		home = (LinearLayout) findViewById(R.id.home);
		gamebox = (LinearLayout) findViewById(R.id.gamebox);
		team = (LinearLayout) findViewById(R.id.team);
		more = (LinearLayout) findViewById(R.id.more);
		
	}
	/**
	 * 适应不同分辨率 设置焦点控件的宽度 
	 */
	private void suitScreen(){
		getWindowManager().getDefaultDisplay().getMetrics(_dm);
		_tab_selector = (ImageView) findViewById(R.id.tab_selector);
	      LayoutParams  para = _tab_selector.getLayoutParams();
        para.height = 60;  
        para.width = _dm.widthPixels>>2; //我底部四个按键所以 每个占1/4宽度
        _tab_selector.setLayoutParams(para);  
	}

	// 在主界面中显示其他界面
	public void showView(int flag) {
		switch (flag) {
		case 0:
			showHome();
			break;
		case 1:
			showGamebox();
			break;
		case 2:
			showTeam();
			break;
		case 3:
			showMore();
			break;
		default:
			break;
		}
	}
	/**
	 * 根据不同的temp_flag,flag 生成不同的animation,主要是设置fromX和toX
	 */
	public void animationShow(){
		if(temp_flag!=flag){
		System.out.println("fromX:"+temp_flag/4f+",toX::"+flag/4f);
		AnimationSet as = new AnimationSet(true);
		TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, temp_flag/4f, Animation.RELATIVE_TO_PARENT, flag/4f, Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
		ta.setDuration(500);
		as.setFillAfter(true);
		as.addAnimation(ta);
		_tab_selector.startAnimation(as);
		temp_flag = flag;
		}
	}
	public void showHome() {
		bodyView.removeAllViews();
		bodyView.addView(getLocalActivityManager().startActivity("home",
				new Intent(ActsGroup.this, Home_Activity.class)).getDecorView());
		animationShow();
	}

	public void showGamebox() {
			bodyView.removeAllViews();
			bodyView.addView(getLocalActivityManager().startActivity(
					"gamebox", new Intent(ActsGroup.this, GameBox_Activity.class))
					.getDecorView());
			animationShow();
	}

	public void showTeam() {
		bodyView.removeAllViews();
		bodyView.addView(getLocalActivityManager().startActivity("team",
				new Intent(ActsGroup.this, GameBox_Activity.class)).getDecorView());
		animationShow();
	}
	public void showMore() {
		bodyView.removeAllViews();
		bodyView.addView(getLocalActivityManager().startActivity("more",
				new Intent(ActsGroup.this, GameBox_Activity.class)).getDecorView());
		animationShow();
	}
}

 最后的效果是 当你点击不同的底部tab 高亮块儿(选择焦点)会移动到相应位置.

gif效果不太好,动的比较快,大家就看看意思吧,实际效果和网易新闻、机锋市场等应用的效果一样!


 

http://androiddada.iteye.com/

有什么问题可以留言~

1 楼 mjbb 2011-11-18  
这gif图片是用什么工具实现的啊?
2 楼 libo19881179 2011-11-18  
mjbb 写道
这gif图片是用什么工具实现的啊?

豌豆荚 呵呵
3 楼 陈文景 2011-11-25  
代码敢不敢给完整??
4 楼 libo19881179 2011-11-25  
mjbb 写道
这gif图片是用什么工具实现的啊?

这就是完整的 其他的也不是这里用到的了

    
[3] 多线程上载文件
    来源: 互联网  发布时间: 2014-02-18
多线程下载文件
(1)
public class MultiThreadDownload extends Thread {

    //定义的一些常量变量,看名字就知道什么意思了

private static final int BUFFER_SIZE = 1024;

private int blockSize;

private int threadNum = 5;

private int fileSize;

private int downloadedSize;

String urlStr, threadNo, fileName;

private String savePath;

private int downloadPercent = 0 , downloadSpeed = 0, usedTime=0;

private long startTime,curTime;

private boolean completed = false;

    //用URL,保存路径,保存名称来构造。

public MultiThreadDownload(String URL, String savePath, String fileName) {

this.urlStr = URL;

this.savePath = savePath;

this.fileName = fileName;

}



@Override

public void run() {

FileDownloadThread[] fds = new FileDownloadThread[threadNum];

try {

URL url = new URL(/blog_article/urlStr/index.html);

URLConnection conn = url.openConnection();

fileSize = conn.getContentLength();

blockSize = fileSize / threadNum;

File file[] = new File[threadNum];

                    //根据默认的线程数,或者自己修改设置的线程数来分块,创建分块后的文件块

for (int i = 0; i < threadNum; i++) {

file[i] = new File(savePath + fileName + ".part"

+ String.valueOf(i));

                            //将分块的文件交给每个线程处理,最后一块应该大于等于平均块,因为可能有余数

FileDownloadThread fdt = new FileDownloadThread(url, file[i], i

* blockSize, (i + 1) != threadNum ? ((i + 1)

* blockSize - 1) : fileSize);

fdt.setName("Thread" + i);

fdt.start();

fds[i] = fdt;

}

startTime = System.currentTimeMillis();

                    //获取起始下载的时间,用次来计算速度。

boolean finished = false;

while (!finished) {

downloadedSize = 0;

finished = true;

for (int i = 0; i < fds.length; i++) {

downloadedSize += fds[i].getDownloadSize();

if (!fds[i].isFinished()) {

finished = false;

}

}

                            //计算下载的百分比

downloadPercent = (downloadedSize*100)/fileSize;

                            //获取当前时间,计算平均下载速度

curTime = System.currentTimeMillis();

usedTime =(int)((curTime-startTime)/1000);

if(usedTime==0)

usedTime =1;

downloadSpeed = (downloadedSize/usedTime)/1024;

sleep(1000);

}

                   //这个是分块下载完成的标志

completed = true;

                    //进行模块整合

RandomAccessFile raf = new RandomAccessFile(savePath + fileName,

"rw");

byte[] tempbytes = new byte[BUFFER_SIZE];

InputStream in = null;

int byteread = 0;

for (int i = 0; i < threadNum; i++) {

in = new FileInputStream(file[i]);

while ((byteread = in.read(tempbytes)) != -1)

{

raf.write(tempbytes, 0, byteread);

}

                            //每次整合完一块就删除一块。

in.close();

file[i].delete();

}

raf.close();

System.out.println(getName() + " end");

} catch (Exception e) {

// TODO: handle exception

}

}

   //获取下载百分比

public int getDownloadPercent(){

return this.downloadPercent;

}

   //获取下载速度

public int getDownloadSpeed(){

return this.downloadSpeed;

}

   //修改默认线程数

public void setThreadNum(int threadNum){

this.threadNum = threadNum;

}

    //分块下载完成的标志

public boolean isCompleted(){

return this.completed;

}

}

(2)
public class FileDownloadThread extends Thread {
private static final int BUFFER_SIZE = 1024;
private URL url;
private File file;
private int startPosition;
private int endPosition;
private int curPosition;
private boolean finished = false;
private int downloadSize = 0;
//分块构造函数
public FileDownloadThread(URL url, File file, int startPosition,
int endPosition) {
this.url = url;
this.file = file;
this.startPosition = startPosition;
this.curPosition = startPosition;
this.endPosition = endPosition;
}
public void run() {
BufferedInputStream bis = null;
RandomAccessFile fos = null;
byte[] buf = new byte[BUFFER_SIZE];
URLConnection con = null;
try {
//打开URL连接
con = url.openConnection();
con.setAllowUserInteraction(true);
//判断是否该文件存在,如果存在且下载完成,直接返回。
if ((file.length() + startPosition) == endPosition) {
this.finished = true;
}
//文件未下载完成,获取到当前指针位置,继续下载。
else {
con.setRequestProperty("Range", "bytes="
+ (startPosition + file.length()) + "-" + endPosition);
fos = new RandomAccessFile(file, "rw");
fos.seek(file.length());
bis = new BufferedInputStream(con.getInputStream());
while (curPosition < endPosition) {
int len = bis.read(buf, 0, BUFFER_SIZE);
if (len == -1) {
break;
}
fos.write(buf, 0, len);
curPosition = curPosition + len;
if (curPosition > endPosition) {
downloadSize += len - (curPosition - endPosition) + 1;
} else {
downloadSize += len;
}
}
this.finished = true;
bis.close();
fos.close();
}
} catch (IOException e) {
System.out.println(getName() + " Error:" + e.getMessage());
}
}
public boolean isFinished() {
return finished;
}
public int getDownloadSize() {
return downloadSize;
}
}
(3)DownActivity
public class DownActivity extends Activity {
private String url="http://download.eoemarket.com/app?id=9449&client_id=114&channel_id=115";
private String savepath="/sdcard/";
private String savename="downfile.apk";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);
MultiThreadDownload down=new MultiThreadDownload(url,savepath,savename);
down.start();

}
}

    
最新技术文章:
数据库 iis7站长之家
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3