首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android imageview展示不了图片

2013-10-10 
android imageview显示不了图片版本2.0xml文件?xml version1.0 encodingutf-8?LinearLayoutxmlns

android imageview显示不了图片
版本2.0
xml文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <ImageView android:id="@+id/UIimg1" 
    android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>

java文件
package slash.UISample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class ImageViewSample extends Activity{
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ImageView iv1;
        iv1=(ImageView)findViewById(R.id.UIimg1);
        iv1.setImageResource(R.drawable.slash);
        setContentView(iv1);
    }
}

slash.png文件也放在了res下三个drawable文件夹里面了
运行的时候提示错误。。以前是好的,不知道为啥呢


[解决办法]
得先setContentView(R.layout.你的xml文件名);才能findViewById(R.id.UIimg1);
[解决办法]
换成setBackgroundResource试试

热点排行