1.Shader

Android 笔记.代码段_第1张图片

http://www.cnblogs.com/snake-hand/archive/2012/02/17/2454392.html


2.SparseArray 替代 HashMap 针对<interger object>

http://liuzhichao.com/p/832.html

3.onCLick

if (System.currentTimeMillis() - mLastClickTime < 300) {      // in order to avoid user click bottom too quickly      return;  }    if (!button.isEnabled())      return;    mLastClickTime = System.currentTimeMillis();  mLastButtonId = button.getId(); 

这样写,在一般场景下会更严谨,防止一些重复点击之类的操作,可以根据自己的情况,在进行添加.

4.TextView跑马灯

android:ellipsize="marquee"  android:marqueeRepeatLimit="marquee_forever"  android:singleLine="true"  

这个跑马灯需要在获取焦点的时候才能有效果.

不获取焦点也有跑马灯效果.

自定义一个TextView,它继承TextView,并且重写isFocuse()方法,让它永远返回true.


5.SlidingDrawer 点击事件传递到下面布局的问题.

今天看到一个,在使用了SlidingDrawer ,open状态下,仍然能触发抽屉覆盖的View点击事件.

解决办法.在content 添加android:clickable="true" 属性. 猜测应该是因为 默认的content没有任何事件,就传递到下面.


6.Android 4.0 HttpURLConnection 下载失败问题

http://blog.csdn.net/mmmlllii/article/details/8000081


7.View高度获取

在OnCreate()方法中获取控件的高度和宽度,需要使用的一个观察者(否则得到的height, paddingTop等数据为0,因onCreate()执行时,控件还未加载完成)

ViewTreeObserver vto = imageview.getViewTreeObserver();        vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {            @Override            public void onGlobalLayout() {                // 此句若不执行,不影响控件宽高的获取结果,但是当前的onGlobalLayout()会执行多次,执行此句,当前方法只会执行一次                imageview.getViewTreeObserver().removeGlobalOnLayoutListener(                        this);                Log.i("TAG", imageview.getMeasuredHeight()                        + " -- - " + imageview.getHeight());            }        });

8.页面跳转动画android:minSdkVersion="8"

Intent intent = new Intent(TransitionActivity.this, DeviceActivity.class);                startActivity(intent);                finish();                //页面切换 -- 淡入淡出效果                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

9.设置汉字粗体

TextView title = new TextView(context);TextPaint paint = title.getPaint();paint.setFakeBoldText(true); 

10.Eclipse 调用 compatibility 不能创建新项目

Android 笔记.代码段_第2张图片

之前一直用的是MotoDev开发,没有遇到类似的问题.有次帮同事搭建新环境,安装了Eclipse,创建新项目时,就会出现这个问题. 提示的是我缺少android-compatibility 文件.

但其实我是已经下载过的.

点击文档查看一下.文档这一段,在想想自己的下载目录,知道了吧.

When done, all files (including source code, samples, and the.jarfiles) are saved into the<sdk>/extras/android/support/directory. This directory contains each of the different support libraries, such as the library for API level 4 and up and the library for API level 13 and up, each named with the respective version (such asv4/).

我们只需要把 ~/android-compatibility 下的文件复制到 ~/extras/android/support/ 下,再Check 就好了.

11. 4.0,访问网络不能在主程序中进行

http://geeksun.iteye.com/blog/1447708

12.Dialog宽度设置.

在做项目中,有时候会遇到Dialog不受控制的问题.可以通过以下代码实现. 但是有个问题就是不够灵活.
WindowManager m = getWindowManager();              Display d = m.getDefaultDisplay();  //为获取屏幕宽、高                        LayoutParams p = getWindow().getAttributes();  //获取对话框当前的参数值       Point outSize = new Point();  d.getSize(outSize);    Log.i(TAG, outSize.x + "-" + outSize.y);  p.width = (int) (outSize.x * 0.6);      p.alpha = 1.0f;            p.dimAmount = 0.7f;    p.gravity = Gravity.CENTER;  getWindow().setAttributes(p);   

13.Android 4.0 HttpURLConnection 下载失败问题

URL u = new URL(url);  HttpURLConnection c = (HttpURLConnection) u.openConnection();  c.setRequestMethod("GET");  c.setDoOutput(true);  c.connect();  (new File(FileUtils.getCachePath())).mkdirs();  FileOutputStream f = new FileOutputStream(new File(file));  InputStream in = c.getInputStream();  
之前一直使用的这套代码做下载部分的实现.但是今天主管告诉我应用在4.0上出现问题. 查看代码后发现是图片下载失败的问题.
在4.0 上 c.getInputStream();会报 java.io.FileNotFoundException. 解决办法是注释掉c.setDoOutput(true);.

http://comments.gmane.org/gmane.comp.handhelds.android.devel/195330

14.Android 4.0 WebView loadData 加载中文乱码

之前使用过loadData这种方式加载Html代码段.今天写一个功能需要使用,但是在我的手机(4.04)上却出现了中文乱码.无论如何设置编码,都无法发解决. baidu一下,解决办法是 使用loadDataWithBaseURL. 解释:点击打开链接
15.Android ListView 点击后刷新. <item name="android:choiceMode">singleChoice</item> 这个标识ListView 为单选的属性.今天在开发的时候,发现点击完后,总会引发item里的图片再次刷新. 刚开始以为是Adapter的问题... 找了半天,去掉这个属性就好了.

16.Webview--让加载进来的页面自适应手机屏幕分辨率居中显示.

让Webview加载的页面居中显示有我知道的俩种方法

第一种:

[java]
WebSettings settings = webView.getSettings();
settings.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
LayoutAlgorithm是一个枚举用来控制页面的布局,有三个类型:

1.NARROW_COLUMNS:可能的话使所有列的宽度不超过屏幕宽度

2.NORMAL:正常显示不做任何渲染

3.SINGLE_COLUMN:把所有内容放大webview等宽的一列中

用SINGLE_COLUMN类型可以设置页面居中显示,页面可以放大缩小,但这种方法不怎么好,有时候会让你的页面布局走样而且我测了一下,只能显示中间那一块,超出屏幕的部分都不能显示。

第二种方法:

[java]
//设置加载进来的页面自适应手机屏幕
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(true);
第一个方法设置webview推荐使用的窗口,设置为true。第二个方法是设置webview加载的页面的模式,也设置为true。

这方法可以让你的页面适应手机屏幕的分辨率,完整的显示在屏幕上,可以放大缩小。
推荐使用第二张方法


更多相关文章

  1. android 页面跳转(intent)
  2. android 查找联系人方法(支持首拼,全拼,英文)
  3. Android之TabHost的几种使用方法
  4. Android保持屏幕常亮的方法总结
  5. Android中RadioGroup RadioButton CheckBox多选按钮实现方法以及
  6. Android-Intent的使用方法详解
  7. Android将Uri转化为文件路径的方法
  8. android HTTP post方法时,如何使用cookies
  9. Android NDK之----- C调用Java [GetMethodID方法的使用]

随机推荐

  1. minSdkVersion各个版本号对应android版本
  2. android添加广告之--admob
  3. Android中的背景音频与MediaSessionCompa
  4. Android(安卓)ScreenShot 屏幕截图
  5. Android(安卓)Framework 基础
  6. Android(安卓)横向选择器(HorizontalPick
  7. android 下载安装并打开apk
  8. Android(安卓)SharedPreferences一般的读
  9. android美化对话框
  10. Android(安卓)TextView支持的HTML标签