为什么ImageView中显示不了位图文件?

iceli iceli 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
布局文件test_bitmap.xml,添加两个ImageView组件来显示图标,其中第一个直接引用g1.jpg,第二个在java中进行设置。
<?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"
android:background="#000000"
>

<TextView
android:text="测试位图资源"
android:id="@+id/bitmapTextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>

<ImageView
android:id="@+id/bitmapImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/g1"></ImageView>

<ImageView
android:id="@+id/bitmapImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ImageView>

</LinearLayout>

创建TestBitmapActivity类
package com.amaker.ch03_resource.drawable;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;

public class TestBitmapActivity extends Activity {
private ImageView myImageView;

public void onCreat(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.test_bitmap);
myImageView=(ImageView)findViewById(R.id.bitmapImageView02);
Resources r=getResources();
Drawable d=r.getDrawable(R.drawable.moto);
myImageView.setImageDrawable(d);
}

}

没有错误,但是位图文件不显示,窗口是空白的。本人刚学android,请问是什么原因?
...全文

相关推荐

评论 24
收藏 已收藏
分享
返回顶部
iceli
Android 80,490 成员 91,375 内容