5.关于尺寸单位

Android默认160dots per inch(在屏幕dpi为160的时候,1 dip == 1 px)
有的手机是120 per inch,density的值为120/160=0.75(此时1 dip == 0.75 px)
有的手机是240 per inch,density的值为240/160=1.5(此时1 dip == 1.5 px)
编辑资源文件时候view的尺寸一定用dip,字体用sp
dips * density = pixels
必须直接指定的话,可通过dip转换,如下:
final float scale = getContext().getResources().getDisplayMetrics().density;
mGestureThreshold = (int) (GESTURE_THRESHOLD_DIP * scale + 0.5f);

22.禁止EditText自动弹出软键盘

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);


21.android:duplicateParentState

微信的用户信息页面点击后整个ViewGroup背景变绿,右边向右的三角形view变白,可以使用这个属性实现

如果设置此属性,将直接从父容器中获取绘图状态(光标,按下等)。 注意仅仅是获取绘图状态,而没有获取事件,也就是你点一下LinearLayout时Button有被点击的效果,但是不执行点击事件。

参考:http://usrcc.diandian.com/post/2011-09-29/5379185

19.drawninepatch工具的使用方法

在左边和上边加一条黑色线控制的是可拉伸区域。右边和下边控制的是内容区域。这个工具在一张图片中间有一块内容而又要防止这块内容拉伸的时候,所起作用非常明显。按住shift点击鼠标可以消除黑色线。

工具的右侧展示的是拉伸的预览效果,从上到下分别是纵向拉伸、横向拉伸、整体拉伸。对工具的使用还需要进一步探索。

20.Android屏幕分辨率详解(VGA、HVGA、QVGA、WVGA、WQVGA)

这些术语都是指屏幕的分辨率。
VGA:Video Graphics Array,即:显示绘图矩阵,相当于640×480 像素;
HVGA:Half-size VGA;即:VGA的一半,分辨率为480×320;
QVGA:Quarter VGA;即:VGA的四分之一,分辨率为320×240;
WVGA:Wide Video Graphics Array;即:扩大的VGA,分辨率为800×480像素;
WQVGA:Wide Quarter VGA;即:扩大的QVGA,分辨率比QVGA高,比VGA低,一般是:400×240,480×272;

发展历程不一样,wm的手机一开始作为商务机,分辨率就是320*240,后边提高到640*480,再到后来的800*480。HVGA没有作为wm手机的重点,或者说基本忽略了在这个分辨率级别。
再谈谈android,我个人认为安卓是效仿iphone的设计思路。
1,HVGA基本上属于性价比比较好的方案。分辨率适中,不像320*240的颗粒感那样严重。因为如果提高分辨率就要提高机器的图像处理组件,也就是对硬件的要求相应提高,价格自然是不低。
2,谷歌手机一开始推广就是用这个分辨率,例如G1,G2等都是采用HVGA的分辨率。
3,现在android的软件基本上都会自动适应HVGA(还包含别的,例如VGA,WVGA等,这个就要看软件作者的了)

18.LinearLayout里面使用weight的效果


<LinearLayout            xmlns:android="http://schemas.android.com/apk/res/android"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_gravity="center"            android:background="#AABBCC"            android:orientation="horizontal" >            <TextView                android:id="@+id/title"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_weight="1"                android:text="wrap_content"                android:textColor="#FFFFFFFF"                android:textSize="22px" />            <Button                android:id="@+id/view_btn"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_gravity="right"                android:layout_weight="1"                android:text="test" />        </LinearLayout>


17.一个LinearLayout中有一个ImageView和一个TextView,点击更换背景的xml文件中只设置LinearLayout的背景,点击没有效果

<LinearLayout            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_weight="1"            android:background="@drawable/list_selector"            android:gravity="center_horizontal"            android:orientation="vertical"            android >            <ImageView                android:id="@+id/iv_animation"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="#bb328EAE"                android:contentDescription="@string/app_name"                android:padding="@dimen/normal_padding"                android:src="@drawable/ic_launcher" />            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="@string/AsyncTask"                android:textColor="#ff0686b5"                android:textSize="14.0sp" />        </LinearLayout>


16.Rotate的xml文件编写方法。动画资源文件中的单位

<rotate android:fromDegrees="0"android:toDegrees="+350"android:pivotX="50%"android:pivotY="50%"android:duration="3000"/>androidpivotX的值共有三红设置方法:1.android:pivotX="50"这种方法使用绝对位置定位;2.android:pivotX="50%"这种方法相对于控件本身定位;3.android:pivotX="50%p"这种方法相对于控件的父控件定位;

15.color资源的使用注意

在color中定义的color资源#AARRGGBB的颜色,

在代码中set颜色的时候直接写R.color.*和

getResources().getColor(R.color.*);的效果是不一样的。务必注意

14.逐帧动画资源文件模板

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/selected" android:oneshot="false" >    <item android:drawable="@drawable/horse1" android:duration="300"/><item android:drawable="@drawable/horse2" android:duration="300"/><item android:drawable="@drawable/horse3" android:duration="300"/><item android:drawable="@drawable/horse4" android:duration="300"/><item android:drawable="@drawable/horse5" android:duration="300"/><item android:drawable="@drawable/horse6" android:duration="300"/></animation-list>


13.java命令行编译多个源文件

javac -d . Example1.java Example2.java; Example1是主类,要用到Exmaple2
执行:java com.example.Example1; 执行时要加上完整包名

13.1命令行编译使用外部jar包

javac -cp jdom.jar -d . IFlow.java NetworkUtil.java

执行

java -classpath jdom.jar; com.bu.qs.IFlow ;注意空格和分号;

13.2java将类文件打成jar包

jar -cvf class.jar com\test\unityforandroid\*

class.jar表示生成的jar名字

*表示所有的class文件

13.3警告:编码 GBK 的不可映射字符

由于JDK是国际版的,在编译的时候,如果我们没有用-encoding参数指定我们的JAVA源程序的编码格式,则javac.exe首先获得我们操作系统默认采用的编码格式,也即在编译java程序时,若我们不指定源程序文件的编码格式,JDK首先获得操作系统的file.encoding参数(它保存的就是操作系统默认的编码格式,如WIN2k,它的值为GBK),然后JDK就把我们的java源程序从file.encoding编码格式转化为JAVA内部默认的UNICODE格式放入内存中。然后,javac把转换后的unicode格式的文件进行编译成.class类文件,此时.class文件是UNICODE编码的,它暂放在内存中,紧接着,JDK将此以UNICODE编码的编译后的class文件保存到我们的操作系统中形成我们见到的.class文件。对我们来说,我们最终获得的.class文件是内容以UNICODE编码格式保存的类文件,它内部包含我们源程序中的中文字符串,只不过此时它己经由file.encoding格式转化为UNICODE格式了。当我们不加设置就编译时,相当于使用了参数:javac -encoding gbk XX.java,当然就会出现不兼容的情况。解决办法是:应该使用-encoding参数指明编码方式:javac -encoding UTF-8 XX.java

12.WebView load html文档

mWebView.getSettings().setDefaultTextEncodingName("UTF-8");
mWebView.loadData(it.getStringExtra(CONTENT), "text/html", "UTF-8");

11.ListView 中item的起始位置

当没有设置header的时候是从0开始;设置headerView的情况下,item是从1开始的。

10.TextView添加下划线的方法

①在代码中实现
mLinkText.setText(Html.fromHtml("<u>"+mLinkUrl+"</u>"));
②在资源文件中
<string name="helloworld"><u>yesorno</u></string>

9.省资源的设置背景方法

<?xml version="1.0" encoding="utf-8"?><bitmap android:src="@drawable/bg" android:tileMode="repeat"  xmlns:android="http://schemas.android.com/apk/res/android" />


bg为一个非常小的图片,tileMode重复绘制。

8.常用的一些常量

View.GONE,VISIBLE,INVISIBLE

ScaleType的常量如7.

LayoutParams的常量ViewGroup.LayoutParams.FILL_PARENT,MATCH_PARENT,WRAP_CONTENT

8.3 ActionBar的常量NAVIGATION_MODE_LIST弹出菜单,NAVIGATION_MODE_STANDARD,NAVIGATION_MODE_TABS选项卡

8.4MenuItem的常量

SHOW_AS_ACTION_ALWAYS
SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
SHOW_AS_ACTION_IF_ROOM
SHOW_AS_ACTION_NEVER
SHOW_AS_ACTION_WITH_TEXT

7.ImageVew的ScaleType属性

从网络上获取的图片尺寸大小不一,可以设置这个属性,保持一样大小。这是一个枚举型常量可以取值:

CENTER, CENTER_CROP, CENTER_INSIDE, FIT_CENTER, FIT_END, FIT_START, FIT_XY, MATRIX

iv.setScaleType(ImageView.ScaleType.FIT_XY);即可让图片适应宽高一样大了,不过有拉伸变形。

具体参考http://hi.baidu.com/kirahai/item/b49ebf5e53eeb63733e0a9f9

8.ViewPager和一个进度条模板

<RelativeLayout        android:layout_width="wrap_content"        android:layout_height="fill_parent" >        <ProgressBar            android:id="@+id/pb_loading"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_centerInParent="true" />        <android.support.v4.view.ViewPager            android:id="@+id/vp_servicetab"            android:layout_width="wrap_content"            android:layout_height="fill_parent"            android:layout_gravity="center"            android:layout_weight="1.0"            android:background="#000000"            android:flipInterval="30"            android:persistentDrawingCache="animation"            android:visibility="invisible" />    </RelativeLayout>

<FrameLayout        android:layout_width="wrap_content"        android:layout_height="fill_parent" >        <android.support.v4.view.ViewPager            android:id="@+id/vp_servicetab"            android:layout_width="wrap_content"            android:layout_height="fill_parent"            android:layout_gravity="center"            android:layout_weight="1.0"            android:background="#000000"            android:flipInterval="30"            android:persistentDrawingCache="animation"             />                <ProgressBar            android:id="@+id/pb_loading"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center"             />    </FrameLayout>

6.TextView实现文本内容滚动

6.1用ScrollView或者HorizontalScrollView嵌套即可;前者实现垂直滚动,后者实现水平滚动

6.2如果想让TextView的文本无论多长都只有1行的话 singleLine为true即可,用ellipsize属性可以出现一个省略号,表示该TextView还有更多的内容,此属性可以取的值有start,middle,end,none,marquee,最后一个效果为走马灯。

最后一个效果试了试,不起作用,马灯没走,如下设置才会走马灯,那个marqueeRepeatLimit是个int值,如下就是不停的走,那个水平滚动为默认,不设置也可以。手机Android2.3测试OK

<TextView android:layout_width="100px"        android:layout_height="wrap_content"        android:textColor="@android:color/white"         android:ellipsize="marquee"         android:focusable="true"         android:marqueeRepeatLimit="marquee_forever"         android:focusableInTouchMode="true"         android:scrollHorizontally="true"        android:text="she is the one that you never forget she is the heaven sent angel you met."        >    </TextView>


1.ListView的使用

android:cacheColorHint="ffffffff"或者listView.setCacheColorHint(Color.alpha(255));//按住时候没有阴影

android:divider="#255"//分割线透明

android:fadingedge="none"边缘无阴影

代码相关:(此处为引用他人博客,向作者致谢)

在ListView里,HeaderView和FooterView也占一行,与其他的item一样,可以点击,有索引,HeaderView的索引为0.如果要使这两项不可点击,可以使用下面的方法:

publicvoid addFooterView(View v,Object data, boolean isSelectable) publicvoid addHeaderView(View v,Object data, boolean isSelectable)

如果在view里已经填充数据,第二个参数可以为空,第三个参数设为false,即不可选择

通用属性:

android:hint="提示:请输入用户名" //edittext常用
android:visibility="gone"或者setVisibility(View.GONE) //View.GONE 一个不占空间,彻底没了。
android:visibility="invisible"或者setVisibility(View.INVISIBLE) //View.INVISIBLE 区别是一个占空间,只是看不见而已

总结:

(1)drawable-hdpi里面存放高分辨率的图片,如WVGA (480x800),FWVGA (480x854)

(2)drawable-mdpi里面存放中等分辨率的图片,如HVGA (320x480)

(3)drawable-ldpi里面存放低分辨率的图片,如QVGA (240x320)

有layout的属性是本控件在容器中的位置没有layout的属性是控件中的内容的位置

Strings.xml中关于使用多个空格的方法:&#160; //想要多个空格就多加不要忘记分号

2.关于透明度

颜色和不透明度(alpha)值以十六进制表示法表示。

任何一种颜色的值范围都是0到255(00到ff)。

对于alpha,00表示完全透明,ff表示完全不透明。

表达式顺序是“aabbggrr”,其中“aa=alpha”(00到ff);“bb=blue”(00到ff);“gg=green”(00到ff);“rr=red”(00到ff)。

例如,如果您希望对某叠加层应用不透明度为50%的蓝色,则应指定以下值:7fff0000

全透明:指定控件的android:background属性为"@android:color/transparent"

alpha值:android:background="#00000000"

3.LinearLayout中的疑问

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <!-- 线性布局中把一个控件的weight的属性设置为1,即可显示其他控件,什么原理?    height为0dp will performance better! -->    <ListView        android:id="@id/lv_app_recommend"        android:layout_width="fill_parent"        android:layout_height="0.0dp"        android:cacheColorHint="#ffffffff"        android:fadingEdge="none"         android:layout_weight="1">            </ListView>        <Button         android:id="@id/btn_guess_again"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="@string/guess_again"        /></LinearLayout>


4.selector.xml模板

<?xml version="1.0" encoding="utf-8" ?> <selector xmlns:android="http://schemas.android.com/apk/res/android">  <item android:state_window_focused="false"         android:drawable="@drawable/没有焦点时的图片背景" />   <item android:state_focused="true" android:state_pressed="true"         android:drawable=              "@drawable/非触摸模式下获得焦点并单击时的背景图片" />   <item android:state_focused="false" android:state_pressed="true"         android:drawable="@drawable/触摸模式下单击时的背景图片" />   <item android:state_selected="true"         android:drawable="@drawable/选中时的图片背景" />   <item android:state_focused="true"         android:drawable="@drawable/获得焦点时的图片背景" /> </selector> 



Android中的几个标记美化的时候会用到:

<stroke>描边

<corner>角形状

<gradient>渐变色

<padding>内部边距

屏幕的方向:

The orientation of the screen from the user's point of view.

landscape:水平

portrait:垂直

更多相关文章

  1. Android实践 -- Android文件储存系统 应用篇
  2. Android添加资源文件编译,R文件未重新生成解决办法
  3. 转 Android:文件下载和写入SD卡学习小结
  4. android下快速检索出媒体文件所在文件夹
  5. Android属性之build.prop生成过程分析及各系统初始配置修改
  6. ionic3文件目录介绍
  7. android从未安装的apk文件里获取信息(包信息,资源信息)

随机推荐

  1. android 传感器学习笔记 一
  2. 使用httpclient连接https 自签名也可以
  3. android STK Display_TEXT Bug
  4. Android studio3.0 - 解决创建Java工程运
  5. Android旋转动画
  6. android常用布局设置
  7. OpenGL ES教程III之移动变换(原文对照)
  8. Android自定义Dialog(zhuang)
  9. 列出Android设备中所有启动的服务,及判断
  10. Android常见问题(一点一点总结未完成)