当前位置:  编程技术>移动开发
本页文章导读:
    ▪汉语Listview排序        中文Listview排序     . import java.text.Collator; import java.util.Comparator; public class ChineseCharComp implements Comparator { @Override public int compare(Object o1, Object o2) { Collator cllator = Collator.getInstance(ja.........
    ▪ Ip地址自动获取下令        Ip地址自动获取命令 1、cmd下 ipconfig /release2、cmd下 ipconfig /renew ......
    ▪ 浮动窗口成效       浮动窗口效果 import com.yfz.view.MyTextView; import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.WindowManager; import android.view.View.........

[1]汉语Listview排序
    来源: 互联网  发布时间: 2014-02-18
中文Listview排序

 

 

.

import java.text.Collator;
import java.util.Comparator;

public class ChineseCharComp implements Comparator {

    @Override
    public int compare(Object o1, Object o2) {
        Collator cllator = Collator.getInstance(java.util.Locale.CHINA);
        if (cllator.compare(o1, o2) < 0)
            return -1;
        else if (cllator.compare(o1, o2) > 0)
            return 1;
        else
            return 0;
    }

}

 

 

Main.java

 

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class Main extends Activity {
    private static final String TAG = "Main";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ArrayList list = new ArrayList();
        list.add("中国");
        list.add("加拿大");
        list.add("美国");
        list.add("德国");
        list.add("A");
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("more");
        list.add("啊");
        Comparator cmp = new ChineseCharComp();
        Collections.sort(list, cmp);
        Iterator iter = list.iterator();
        while (iter.hasNext()) {
            Log.d(TAG, "----" + iter.next());
        }
    }
}

 

 

 

结果?自己试试把


    
[2] Ip地址自动获取下令
    来源: 互联网  发布时间: 2014-02-18
Ip地址自动获取命令
1、cmd下 ipconfig /release

2、cmd下 ipconfig /renew

    
[3] 浮动窗口成效
    来源: 互联网  发布时间: 2014-02-18
浮动窗口效果
import com.yfz.view.MyTextView;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;


/**
 * 浮动窗口
 * 
 * @author Administrator
 * 
 */
public class TopFrame extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Button button = (Button) findViewById(R.id.bt);

		button.setOnClickListener(onclick);
	}

	private MyTextView tv = null;

	OnClickListener onclick = new OnClickListener() {

		@Override
		public void onClick(View v) {
			if (tv != null && tv.isShown()) {
				WindowManager wm = (WindowManager) getApplicationContext()
						.getSystemService(TopFrame.this.WINDOW_SERVICE);
				wm.removeView(tv);
			}

			show();

		}
	};

	Button btn1 = null;
	Button btn2 = null;

	private void show() {
		Rect frame = new Rect();
		// 这一句是关键,让其在top 层显示
		getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
		MyTextView.TOOL_BAR_HIGH = frame.top;

		WindowManager wm = (WindowManager) getApplicationContext()
				.getSystemService(WINDOW_SERVICE);
		WindowManager.LayoutParams params = MyTextView.params;
		params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
				| WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
		params.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL
				| LayoutParams.FLAG_NOT_FOCUSABLE;

		params.width = WindowManager.LayoutParams.FILL_PARENT;
		params.height = WindowManager.LayoutParams.WRAP_CONTENT;
		params.alpha = 80;

		params.gravity = Gravity.LEFT | Gravity.TOP;
		// 以屏幕左上角为原点,设置x、y初始值ֵ
		params.x = 0;
		params.y = 0;

		tv = new MyTextView(TopFrame.this);
		wm.addView(tv, params);

	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		WindowManager wm = (WindowManager) getApplicationContext()
				.getSystemService(WINDOW_SERVICE);

		 if(tv != null && tv.isShown()){
		 wm.removeView(tv);
		 }

		super.onDestroy();
	}

}

 自定义textView

public class MyTextView extends TextView {
	private final String TAG = MyTextView.class.getSimpleName();
	
	public static int TOOL_BAR_HIGH = 0;
	public static WindowManager.LayoutParams params = new WindowManager.LayoutParams(); 
	private float startX;
	private float startY;
	private float x;
	private float y;
	
	private String text;
	
	WindowManager wm = (WindowManager)getContext().getApplicationContext().getSystemService(getContext().WINDOW_SERVICE);
 
	public MyTextView(Context context) {
		super(context);
		text = "世上只有妈妈好,有妈的孩子像块宝";
		this.setBackgroundColor(Color.argb(90, 150, 150, 150));
		handler = new Handler();
		handler.post(update);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		//触摸点相对于屏幕左上角坐标
		x = event.getRawX();   
	    y = event.getRawY() - TOOL_BAR_HIGH;
	    Log.d(TAG, "------X: "+ x +"------Y:" + y);
	    
	    switch(event.getAction()) {
	    	case MotionEvent.ACTION_DOWN:
	    		startX = event.getX();
	    		startY = event.getY();
	    		break;
	    	case MotionEvent.ACTION_MOVE:
	    		updatePosition();
	    		break;
	    	case MotionEvent.ACTION_UP:
	    		updatePosition();
	    		startX = startY = 0;
	    		break;
	    }
	    
		return true;
	}
	//这儿使得有颜色变化的字体
	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		float1 += 0.001f;
		float2 += 0.001f;	
		
		if(float2 > 1.0){
			float1 = 0.0f;
			float2 = 0.01f;
		}
		this.setText("");
		float len = this.getTextSize() * text.length();
		Shader shader = new LinearGradient(0, 0, len, 0, 
				new int[] { Color.YELLOW, Color.RED },  new float[]{float1, float2},
				TileMode.CLAMP);
		Paint p = new Paint();
		p.setShader(shader);
		p.setTypeface(Typeface.DEFAULT_BOLD);
		canvas.drawText(text, 0, 10, p);
			
	}
	
	private Runnable update = new Runnable() {
        public void run() {
        	MyTextView.this.update();
        	handler.postDelayed(update, 5);
        }
    };
	
	private void update(){
		postInvalidate();
	}
	
	private float float1 = 0.0f;
	private float float2 = 0.01f;
	
	private Handler handler;	

	//更新浮动窗口位置参数
	 private void updatePosition(){
		 // View的当前位置
		 params.x = (int)( x - startX);
		 params.y = (int) (y - startY);
		 wm.updateViewLayout(this, params);
	 }
}

 


    
最新技术文章:
▪Android开发之登录验证实例教程
▪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