`
文章列表
  改变UI中view的位置,用绝对布局比较方便。 import android.widget.AbsoluteLayout.LayoutParams; Random random = new Random(); int left = random.nextInt(1000); int top = random.nextInt(580); Log.i("..........................", "............." + left+ "x" + top); //前两个参数说明控件 ...
  创建菜单,并在点击的某个菜单的时候跟菜单项id去处理逻辑,后面的设置监听的方法也是可以的,不过不建议使用,效率慢 @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub menu.add(0, 1, 0, "append"); menu.add(0, 2, 1, "item2"); menu.add(0, 3, 2, "clear"); ...
public void postData() { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php"); try { // Add your data List<NameValuePair> nameValueP ...
啥都不说了,给一个文件,返回给byte数组 // read the photo file into a byte array... public static byte[] getBytesFromFile(File file) throws IOException { InputStream is = new FileInputStream(file); // Get the size of the file long length = file.length(); // You cannot create an array using a long ...
public static void main(String[] args) throws IOException { URL url = new URL( "http://img.verycd.com/vcgroup/gface/48-48/143661.jpg"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(10 * 1000); conn.setRequestMethod("GE ...
/** * 发出一个GET请求 * @param path 请求的路径,不带参数 * @param params 参数 * @return * @throws Exception */ private static boolean sendGetRequest(String path, Map<String, String> params, String encoding) throws Exception{ // http://192.168.1.10:8080/videoweb/video/manage.do?method=sa ...
// HTTPS SSL COOKIE private static boolean sendPostRequestHttpClient(String path, Map<String, String> params, String encoding) throws Exception{ List<NameValuePair> paramPairs = new ArrayList<NameValuePair>(); if(params!=null && !params.isEmpty()){ for(Map.En ...
  //通过get方式获取网络图片 public static void main(String[] args) throws Exception{ String path = "http://i6.17173.itc.cn/2010/news/chinajoy/2010/mm/small01/s0722cyfs01.jpg"; URL url = new URL(path); //get //post HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn ...
  public static void main(String[] args) throws Throwable { String path = "http://192.168.1.10:8080/videoweb/video/manage.do?method=getXML"; String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><persons><person id=\"23\"><nam ...
  /** * 从输入流读取数据 * @param inStream * @return * @throws Exception */ public static byte[] readInputStream(InputStream inStream) throws Exception{ ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while( (len = inStr ...
Android中集成了一个apache组织提供的一个开源的访问互联网的客户端程序 HttpClient 可以使用它来发送数据 这里有两个方法,是往互联网传送数据时候用的 一个是传送普通文本的,一个是传送带附件的 这两个方法就可以满足我们正常的所有需求了 public class HttpRequester { public static String post(String actionUrl, Map<String, String> params, FormFile[] files) { try { ...
在Android中我们的应用可以灵活的内嵌自己的字体文件,实现各个手机上可以正常的显示个性化文字,我们都知道TextView的setTypeface方法可以设置目标文字的显示特性,比如字体、颜色、粗体、斜体等。我们直接找一个TrueTypeFont的字体文件即.ttf,对于Win32系统的用户可以直接在Windows/fonts文件夹中能找到很多。比如微软雅黑就不错,可是体积太大,由于Android的Assets类有单个文件1MB体积的限制,我们先找个英文字体做测试。这里我们将字体文件android123.ttf放到工程的assets文件夹的fonts目录中。      Typeface tf ...
public void test1() throws XmlPullParserException, IOException { InputStream inStream = new FileInputStream("/mnt/nand/songli.xml"); XmlPullParser xmlParser = XmlPullParserFactory.newInstance() .newPullParser(); xmlParser.setInput(inStream, "utf-8"); int eve ...
1、当点击Menu键时,如果希望弹出菜单,则希望重写的方法如下:     @Override public boolean onCreateOptionsMenu(Menu menu) { // TODO Auto-generated method stub menu.add(0,0,0,"first"); menu.add(0,1,1,"second"); menu.add(0,1,2,"third"); menu.add(1,0,0, ...
DisplayMetrics display =  new DisplayMetrics();     //该方法主要是用于 实例化DisplayMetrics 对象,不能省略。                getWindowManager().getDefaultDisplay().getMetrics(display);           String fenbian = display.widthPixels + " x " + display.heightPixels;           mTextView2 = (TextView) ...
Global site tag (gtag.js) - Google Analytics