当前位置: 编程技术>移动开发
本页文章导读:
▪汉语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
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); } }
最新技术文章: