1. android--由文件名获取文件Id的两种方法
http://blog.csdn.net/shaojie519/article/details/6746716
2. android 分辨率及密度详细
http://blog.csdn.net/to_cm/article/details/7802673
3. android获取设备信息
http://blog.csdn.net/tdk133/article/details/7238277
4. Android px、dp、sp之间相互转换
http://blog.csdn.net/fx_sky/article/details/8588703
5. Supporting Multiple Screens
http://developer.android.com/guide/practices/screens_support.html
6. Android平板上开发应用的一点心得——精确适配不同的dpi和屏幕尺寸
http://www.cnblogs.com/zealotrouge/archive/2012/11/23/2784774.html
经过两个月的开发,发现此方法虽然能精确适配,重读SDK文档却发现我们完全忽略了dp这个单位的意义,由于从不同后缀的文件夹取值,Android系统会自动将设定值缩放,比如想指定100dp的大小,那么到了ldpi就得填入150dp,到了hdpi就得填入66dp以抵消Android的自动缩放,所以推翻这篇文章所记录的方法,现改用:
1、控件全部指定dp。2、文字全部指定sp。3、图片适配全部放入drawable-mdpi中并使用wrap_content,这样在不同屏幕上均能自动缩放,无需按分辨率进行所谓的精确适配。
7. android 状态栏、标题栏、屏幕高度
http://xqjay19910131-yahoo-cn.iteye.com/blog/1435249
8. android给listview设置分割线Divider样式
http://www.blogjava.net/anchor110/articles/362299.html
参考效果图调节布局视图的尺寸和文字大小时,需要将pix和dp进行转换
public static int dip2px(Activity activity, float dipValue) { return (int) (dipValue * (getDensity(activity) / 160f)); } public static int px2dip(Activity activity, float pxValue) { return (int) ((pxValue * 160) / getDensity(activity)); }
不同的平板各自的displayMetrics和deviceInfo不同,
public static void logDisplayMetrics(Activity activity) { DisplayMetrics metric = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metric); int width = metric.widthPixels; // 屏幕宽度(像素) int height = metric.heightPixels; // 屏幕高度(像素) float density = metric.density; // 屏幕密度(0.75 / 1.0 / 1.5) int densityDpi = metric.densityDpi; // 屏幕密度DPI(120 / 160 / 240) Logger.v(TAG, "@logDisplayMetrics. width:" + width + ", height:" + height + ", density:" + density + ", densityDpi:" + densityDpi); } public static void logDeviceInfo() { String sdk = android.os.Build.VERSION.SDK; // SDK号 String model = android.os.Build.MODEL; // 手机型号 String release = android.os.Build.VERSION.RELEASE; // android系统版本号 Logger.v(TAG, "@logDeviceInfo. sdk:" + sdk + ", model:" + model + ", release:" + release); }
华为平板日志
@logDisplayMetrics. width:1280, height:752, density:1.0, densityDpi:160 @logDeviceInfo. sdk:16, model:MediaPad 10 LINK, release:4.1.2
三星平板日志
@logDisplayMetrics. width:1280, height:736, density:1.3312501, densityDpi:213 @logDeviceInfo. sdk:18, model:Nexus 7, release:4.3
ListView的宽度设定为match_parent。
<com.tvie.ivideo.widget.PullToRefreshView android:id="@+id/pullView" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="0dp" android:background="@color/default_bg" android:orientation="vertical" android:paddingRight="1dp" > <ListView android:id="@+id/programList" android:background="@color/default_bg" android:layout_width="match_parent" android:layout_height="match_parent" /> </com.tvie.ivideo.widget.PullToRefreshView>
在程序中打出ListView的高度,
pullToRefreshView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { Logger.v(TAG, "@onLayoutChange. pullToRefreshView.size. width:" + pullToRefreshView.getMeasuredWidth() + ", height:" + pullToRefreshView.getMeasuredHeight()); Logger.v(TAG, "@onLayoutChange. mListView.size. width:" + mListView.getMeasuredWidth() + ", height:" + mListView.getMeasuredHeight()); pullToRefreshView.removeOnLayoutChangeListener(this); } });
当ListView中没有任何内容时,它的高度不为零。
12-06 18:25:54.178: V/TvProgramListFragment(11705): @onLayoutChange. pullToRefreshView.size. width:528, height:630 12-06 18:25:54.178: V/TvProgramListFragment(11705): @onLayoutChange. mListView.size. width:527, height:630