标签:动态添加image
<pre name="code" class="java">实体类:
package com.example.showgetpic;
import android.R.integer;
class ImageBean {
public String path;
private int rightMargin;
private int bottomMargin;
public int getRightMargin() {
return rightMargin;
}
public void setRightMargin(int rightMargin) {
this.rightMargin = rightMargin;
}
public int getBottomMargin() {
return bottomMargin;
}
public void setBottomMargin(int bottomMargin) {
this.bottomMargin = bottomMargin;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
BaseActivity:
/**
* Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.showgetpic;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
public class BaseActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
}
@Override
protected void onResume() {
super.onResume();
// onresume时,取消notification显示
// HXSDKHelper.getInstance().getNotifier().reset();
// umeng
// MobclickAgent.onResume(this);
}
@Override
protected void onStart() {
super.onStart();
// umeng
// MobclickAgent.onPause(this);
}
/**
* 返回
*
* @param view
*/
public void back(View view) {
finish();
}
}
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/ly_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<ImageView
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/topic_plus_pressed" >
</ImageView>
</LinearLayout>Application类:
package com.example.showgetpic;
import android.app.Application;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;
public class IApplication extends Application {
//获取屏幕宽度
public static int getScreenWidth(Context context) {
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
int width = outMetrics.widthPixels;
return width;
}
//获取屏幕密度
public static float getScreenDensity(Context context) {
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
float density = outMetrics.density;
return density;
}
/**
* 获得屏幕高度
*/
public static int getScreenHeight(Context context) {
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
int height = outMetrics.heightPixels;
return height;
}
/**
* 获得状态栏的高度
*/
public static int getStatusHeight(Context context) {
int statusHeight = -1;
try {
Class<?> clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
int height = Integer.parseInt(clazz.getField("status_bar_height")
.get(object).toString());
statusHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e) {
e.printStackTrace();
}
return statusHeight;
}
}
标签:动态添加image
原文地址:http://blog.csdn.net/wuxin782515516/article/details/46331949