杂记
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true">
<ImageView
android:layout_width="50dp"//此时imagview靠gridview左显示
android:layout_width="match_parent"
//靠中显示
android:layout_height="50dip"
android:id="@+id/image"
android:layout_margin="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="123"
android:gravity="center"
android:id="@+id/text5"/>
</LinearLayout>
BitmapFactory.Options:
处理图片太大,内存爆满的情况和缩放的操作
常用方法:
BitmapFactory.Optionsopts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;//设置ture时,BitmapFactory.decodeFile(String path,Options opt)并不会真的返回一个Bitmap给你,它仅仅会把它的宽,高取回来给你,这样就不会占用太多的内存,也就不会那么频繁的发生OOM了,这段代码之后,options.outWidth 和 options.outHeight就是我们想要的宽和高了
BitmapFactory.decodeFile(imageFile, opts);
opts.inSampleSize = 一个整形值 //例如,inSampleSize==2,则取出的缩略图的宽和高都是原始图片的1/2,图片的大小就是原始图片的1/4。
对于任何值<=1的同样处置为1.
opts.inJustDecodeBounds = false;
try {
Bitmap bmp =BitmapFactory.decodeFile(imageFile, opts);
imageView.setImageBitmap(bmp);
}catch (OutOfMemoryError err) {
}
Menu:
1.<item>标签的属性含义如下:
Id:表示菜单项的资源ID
menuCategory:同种菜单项的种类。该属性可取4个值:container、system、secondary和alternative。通过menuCategroy属性可以控制菜单项的位置。例如将属性设为system,表示该菜单项是系统菜单,应放在其他种类菜单项的后面。
orderInCategor:同种类菜单的排列顺序。该属性需要设置一个整数值。例如menuCategory属性值都为system的3个菜单项(item1、item2和item3)。将这3个菜单项的orderInCategory属性值设为3、2、1,那么item3会显示在最前面,而item1会显示在最后面。
title:菜单项标题(菜单项显示的文本)
titleCondensed:菜单项的短标题。当菜单项标题太长时会显示该属性值
icon:菜单项图标资源ID
alphabeticShortcut:菜单项的字母快捷键
numericShortcut:菜单项的数字快捷键
checkable:表示菜单项是否带复选框。该属性可设计为true或false
checked:如果菜单项带复选框(checkable属性为true),该属性表示复选框默认状态是否被选中。可设置的值为true或false
visible:菜单项默认状态是否可视
enable:菜单项默认状态是否被激活
2.<group>标签的属性含义如下:
id:表示菜单组的ID
menuCategory:与<item>标签的同名属性含义相同。只是作用域为菜单组
orderInCategory:与<item>标签的同名属性含义相同。只是作用域为菜单组
checkableBehavior:设置该组所有菜单项上显示的选择组件(CheckBox或Radio Button)。如果将该属性值设为all,显示CheckBox组件;如果设为single,显示Radio Button组件;如果设为none,显示正常的菜单项(不显示任何选择组件)。要注意的是,Android SDK官方文档在解释该属性时有一个笔误,原文是:
Whether the items are checkable. Validvalues: none, all(exclusive/radiobuttons), single(non-exclusive/checkboxes).
相反了,正确应该是
all(non-exclusive/checkboxes),single(exclusive/radiobuttons).
visible:表示当前组中所有菜单项是否显示。该属性可设置的值是true或false
enable:表示当前组中所有菜单项是否被激活。该属性可设置的值是true或false
3.具体使用
在代码中使用
public boolenonCreateOptionsMenu(Menumenu){
MenuInflatemenuInflate = getMenuInflate();
menuInflate.inflate(R.menu.option_menu,menu);
returntrue;
}
app:showAsAction="ifRoom"
app中有一个菜单(menu),showAsAction主要是针对这个菜单的显示起作用的,它有三个可选项 always:总是显示在界面上 never:不显示在界面上,只让出现在右边的三个点中 ifRoom:如果有位置才显示,不然就出现在右边的三个点中
见:http://www.360doc.com/content/14/0629/22/16002580_390830244.shtml