一开始在xml中用gravity和Layout gravity的时候,没有去注意有什么区别,导致在调整界面的时候误用了,总是没法使文字按照要求的位置来显示。
其实从英文字面上也不难理解,Layout gravity我的理解是当前组件对父组件的位置,而gravity是当前组件的内容对当前组件的位置。
下面是设计两行组件左对齐,并且组合在一起居中显示的情况
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/sim_1"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="@+id/sim_icon_1"
android:focusable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="/blog_article/@drawable/zzz_ic_sim1/index.html" />
<TextView
android:id="@+id/carrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_toRightOf="@+id/sim_icon_1"
android:layout_alignTop="@+id/sim_icon_1"
android:text="sim ka"/>
</LinearLayout>
<LinearLayout
android:id="@+id/sim_2"
android:layout_below="@id/sim_1"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="@+id/sim_icon_2"
android:focusable="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="/blog_article/@drawable/zzz_ic_sim2/index.html" />
<TextView
android:id="@+id/carrier2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:layout_toRightOf="@+id/sim_icon_2"
android:layout_alignTop="@+id/sim_icon_2"
android:text="sim ka ghrthrtbv"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
如果你的事apache的服务器,找到你的tomcat目录
在conf/web.xml文件里 添加apk的类型即可。
<!-- ===================== Default MIME Type Mappings =================== -->
...
<mime-mapping>
<extension>zip</extension>
<mime-type>application/zip</mime-type>
</mime-mapping>
...
------------------------------------------
类似上面添加一条:
<mime-mapping>
<extension>apk</extension>
<mime-type>application/vnd.android.package-archive</mime-type>
</mime-mapping>
这样就可以防止apk变成zip格式了。。。
这只是我以前开始搞android事留下的代码,发现还是存在问题的,我现在把代码放出来,仅供参考,如没有帮助就不要看了,
Gallery加载大量图片的时候容易内存溢出,但是如果及时回收不用的图片,在使用的时候再重新加载,这样就不会出现内存溢出的现象了,所以一定要将加载图片的地址保存起来,在加载图片的时候将生成的bitmap对象用图片地址的字符串保存在map里,不用的时候再根据key值回收。
下面是实现的几个主要部分
1、工具类
public class ImageManager {
static int index = 0;
public static ConcurrentHashMap<String, Bitmap> imageMap = new ConcurrentHashMap<String, Bitmap>();
public static String ISFALSE="ISFALSE";
public static String ISTRUE="ISTRUE";
public static List<String[]> getSD(String dir) {
List<String[]> it = new ArrayList<String[]>();
File f = new File(dir);
File[] files = f.listFiles();
if (files != null) {
for (int i = 0; i < files.length; i++) {
String[] s = new String[2];
File file = files[i];
if (file.isFile()) {
if (getImageFile(file.getPath())) {
System.out.println("file " + String.valueOf(file));
s[0] = file.getPath();
s[1] = file.getName();
it.add(s);
}
} else if(file.isDirectory()){
System.out.println("file.isDirectory() " + file.getAbsolutePath());
getSD(String.valueOf(file.getAbsolutePath()));
}
}
}
return it;
}
public static boolean getImageFile(String fName) {
boolean re;
String end = fName
.substring(fName.lastIndexOf(".") + 1, fName.length())
.toLowerCase();
if (end.equals("jpg") || end.equals("gif") || end.equals("png")
|| end.equals("jpeg") || end.equals("bmp")) {
re = true;
} else {
re = false;
}
return re;
}
public static Bitmap getImage(String fileName) {
try {
File file = new File(fileName);
Bitmap bitmap = null;
bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
addImage(fileName, bitmap);
return bitmap;
} catch (Exception e) {
return null;
}
}
public static Bitmap getRefImage(String fileName) {
try {
File file = new File(fileName);
Bitmap bitmap = null;
bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
addImage(fileName, bitmap);
return createReflectionImageWithOrigin(fileName, bitmap);
} catch (Exception e) {
return null;
}
}
public static void addImage(String uri, Bitmap bitmap) {
imageMap.put(uri.toString(), bitmap);
}
private static void clearBitmap(String uri) {
if (imageMap.get(uri) != null) {
System.out.println("remove image:" + uri);
imageMap.get(uri).recycle();
imageMap.remove(uri);
}
}
// 清空左边到0、右边到最后,保留中间
public static List<ImageMessage> clearImage(List<ImageMessage> imageList,
int start, int end) {
if (start >= 0 && end < imageList.size()) {
for (int i = 0; i < start; i++) {
if (imageList.get(i).getIsNull().equals(ISFALSE)) {
imageList.get(i).setIsNull(ISTRUE);
clearBitmap(imageList.get(i).getPath().toString());
clearBitmap(imageList.get(i).getPath().toString() + "1");
clearBitmap(imageList.get(i).getPath().toString() + "2");
imageList.get(i).setImage(null);
}
}
for (int i = end + 1; i < imageList.size(); i++) {
if (imageList.get(i).getIsNull().equals(ISFALSE)) {
imageList.get(i).setIsNull(ISTRUE);
clearBitmap(imageList.get(i).getPath().toString());
clearBitmap(imageList.get(i).getPath().toString() + "1");
clearBitmap(imageList.get(i).getPath().toString() + "2");
imageList.get(i).setImage(null);
}
}
}
return imageList;
}
// 获得带倒影的图片方法
public static Bitmap createReflectionImageWithOrigin(String str,
Bitmap bitmap) {
final int reflectionGap = 0;//原图片与倒影图片之间的缝隙
int width = bitmap.getWidth();
int height = bitmap.getHeight();
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2,
width, height / 2, matrix, false);
addImage(str + "1", reflectionImage);
Bitmap bitmapWithReflection = Bitmap.createBitmap(width,
(height + height / 2), Config.ARGB_8888);
addImage(str + "2", bitmapWithReflection);
Canvas canvas = new Canvas(bitmapWithReflection);
canvas.drawBitmap(bitmap, 0, 0, null);
Paint deafalutPaint = new Paint();
canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);