android显示图片的两种方法
来源:互联网 发布:iphone4s刷机软件 编辑:程序博客网 时间:2024/06/05 18:39
第一种使用xml文件
1.新建android application
2.将要显示的图片img.png放到res/drawable-mdpi目录下
3.打开res/layout目录下的main.xml文件,用如下代码替换
<?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" ><ImageView android:id="@+id/imageView" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@drawable/img" /></LinearLayout>
运行项目即可
第二中直接在java代码里实现
1.新建android application
2.将要显示的图片img.png放到res/drawable-mdpi目录下
3.打开src目录下的java源文件,写入如下代码
import android.app.Activity;import android.graphics.BitmapFactory;import android.os.Bundle;import android.widget.ImageView;public class ImgShow extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ImageView imageView = new ImageView(this); imageView.setImageBitmap( BitmapFactory.decodeResource(getResources(), R.drawable.img)); this.setContentView(imageView); }}运行即可
0 0
- android显示图片的两种方法
- Android EditText显示图片的两种方法
- Android显示动态图片的两种方法
- 循环显示图片的两种方法
- Android 全屏显示的两种方法
- 【Android】Web开发之显示网络图片的两种方法
- 点击按钮显示图片的两种方法
- python 读取并显示图片的两种方法
- python 读取并显示图片的两种方法
- python 读取并显示图片的两种方法
- python 读取并显示图片的两种方法
- python 读取并显示图片的两种方法
- Python读取并显示图片的两种方法
- python 读取并显示图片的两种方法
- 查找显示图片的两行方法
- android 图片旋转实现的两种方法的比较
- Android之进度框的两种显示方法
- android Notification显示通知的两种方法
- powerpivot 2013 PowerPivot 服务应用程序无效或不存在
- java类初始化顺序
- 计蒜客016-爬楼梯
- Node.js 0.12 全解
- 获取网络图片的尺寸大小
- android显示图片的两种方法
- Bing缤纷壁纸
- 折线法
- android图片处理方法
- td中嵌套table,如何让此table完全填充父td
- css通配符“*”及样式重置
- ssh 中使用c3p0 的连接池配置出错 Invalid property 'xxx' of bean class [com.mchange.v2.c3p0.ComboPoo
- 设计模式->单例模式
- 一切成功源于积累——20141220 为什么会每隔100点买盘 低买高卖 是一种求不得的心态