为什么ImageView中显示不了位图文件? imageview位图布局java 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 myImageView = (ImageView) this.findViewById(R.id.bitmapImageView02);myImageView.setImageResource(R.drawable.moto); myImageView=(ImageView)findViewById(R.id.bitmapImageView02); Resources r=getResources(); Drawable d=r.getDrawable(R.drawable.g1); myImageView.setImageDrawable(d);我把你的代码拷来试了下两个都显示第一张图都没问题R.drawable.moto是不是这张图有问题或者你没放到资源文件夹下 图片还是没有显示。图片是在C盘随便搜的。png,jpg格式的都不行。 写错了,应该是imageview.setBitmap吧,语法就有错误 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.moto);myImageView.setImageBitmap(bitmap); 你可以看下你那个Drawable对象是不是为null,还有看下你启动的是不是这个activity 你可以看下你那个Drawable对象是不是为null,还有看下你启动的是不是这个activity <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.amaker.ch03.xml.TextXmlActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>是调用的这个activity,怎么看drawable对象是不是为空? 你可以看下你那个Drawable对象是不是为null,还有看下你启动的是不是这个activity <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.amaker.ch03.xml.TextXmlActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>是调用的这个activity,怎么看drawable对象是不是为空?晕,粘错了 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.amaker.ch03_resource.drawable.TestBitmapActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> 你可以看下你那个Drawable对象是不是为null,还有看下你启动的是不是这个activity <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.amaker.ch03.xml.TextXmlActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>是调用的这个activity,怎么看drawable对象是不是为空?晕,粘错了 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.amaker.ch03_resource.drawable.TestBitmapActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>判断下打印就知道了撒 你的moto是什么格式的?bmp?moto是jpg格式的,g1是png格式的。 你可以看下你那个Drawable对象是不是为null,还有看下你启动的是不是这个activity <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.amaker.ch03.xml.TextXmlActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>是调用的这个activity,怎么看drawable对象是不是为空?晕,粘错了 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.amaker.ch03_resource.drawable.TestBitmapActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>判断下打印就知道了撒 Drawable d=r.getDrawable(R.drawable.moto); if(null==d) Log.d("drawable is null", null); myImageView.setImageDrawable(d);加了打印,logcat.txt没有。 你的moto是什么格式的?bmp?moto是jpg格式的,g1是png格式的。不应该有没问题的啊,你把private ImageView myImageView;改成private ImageView myImageView=null;试试 你的moto是什么格式的?bmp?moto是jpg格式的,g1是png格式的。不应该有没问题的啊,你把private ImageView myImageView;改成private ImageView myImageView=null;试试还是没显示 重新建了工程,把之前的核心代码粘贴进去就ok了。以前是用了以前的工程,只改了src和layout下面的文件。下面是改后的代码<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".TestBitmapActivity" > <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent"> <TableRow android:gravity="center_horizontal"> <TextView android:text="测试位图资源" android:id="@+id/bitmapTextView01" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> </TableRow> <TableRow android:gravity="center_horizontal"> <ImageView android:id="@+id/bitmapImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/g1"></ImageView> </TableRow> <TableRow android:gravity="center_horizontal"> <ImageView android:id="@+id/bitmapImageView02" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView> </TableRow> </TableLayout></RelativeLayout>package com.amaker.ch03_drawable;import com.amaker.ch03_drawable.R;import android.os.Bundle;import android.app.Activity;import android.content.res.Resources;import android.graphics.drawable.Drawable;import android.util.Log;import android.view.Menu;import android.widget.ImageView;public class TestBitmapActivity extends Activity { private ImageView myImageView=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test_bitmap); myImageView=(ImageView)this.findViewById(R.id.bitmapImageView02); //Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.moto); //myImageView.setImageResource(R.drawable.moto); Resources r=getResources(); Drawable d=r.getDrawable(R.drawable.moto); if(null==d) Log.d("drawable is null", null); myImageView.setImageDrawable(d); }} 问个Socket编程的问题!!!! TextView和EditText 问题 android Activity跳转时崩溃 如何处理弹出窗口AlertDialog.Builder的返回键事件 android短信listview中长按一条短信,再横屏以后选择的数据改变 用opengl做了一个动画效果,想知道怎么让它进行快一点 android中如何分析URL 比如我想调用自己已经安装好了的apk软件? 请神帮忙解释getContentResolver().update参数 请教一下Socke 接收的问题 将原始xml内容显示在TextView中出错 Button设置背景图片和文字的小问题
myImageView.setImageResource(R.drawable.moto);
Resources r=getResources();
Drawable d=r.getDrawable(R.drawable.g1);
myImageView.setImageDrawable(d);
我把你的代码拷来试了下两个都显示第一张图都没问题
R.drawable.moto
是不是这张图有问题或者你没放到资源文件夹下
图片是在C盘随便搜的。png,jpg格式的都不行。
myImageView.setImageBitmap(bitmap);
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.amaker.ch03.xml.TextXmlActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
是调用的这个activity,怎么看drawable对象是不是为空?
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.amaker.ch03.xml.TextXmlActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
是调用的这个activity,怎么看drawable对象是不是为空?
晕,粘错了
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.amaker.ch03_resource.drawable.TestBitmapActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.amaker.ch03.xml.TextXmlActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
是调用的这个activity,怎么看drawable对象是不是为空?
晕,粘错了
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.amaker.ch03_resource.drawable.TestBitmapActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
判断下打印就知道了撒
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.amaker.ch03.xml.TextXmlActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
是调用的这个activity,怎么看drawable对象是不是为空?
晕,粘错了
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.amaker.ch03_resource.drawable.TestBitmapActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
判断下打印就知道了撒 Drawable d=r.getDrawable(R.drawable.moto);
if(null==d)
Log.d("drawable is null", null);
myImageView.setImageDrawable(d);加了打印,logcat.txt没有。
不应该有没问题的啊,你把private ImageView myImageView;改成private ImageView myImageView=null;试试
不应该有没问题的啊,你把private ImageView myImageView;改成private ImageView myImageView=null;试试还是没显示
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".TestBitmapActivity" > <TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:gravity="center_horizontal">
<TextView
android:text="测试位图资源"
android:id="@+id/bitmapTextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</TableRow> <TableRow android:gravity="center_horizontal">
<ImageView
android:id="@+id/bitmapImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/g1"></ImageView>
</TableRow>
<TableRow android:gravity="center_horizontal">
<ImageView
android:id="@+id/bitmapImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></ImageView>
</TableRow>
</TableLayout></RelativeLayout>
package com.amaker.ch03_drawable;import com.amaker.ch03_drawable.R;import android.os.Bundle;
import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Menu;
import android.widget.ImageView;public class TestBitmapActivity extends Activity {
private ImageView myImageView=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_bitmap);
myImageView=(ImageView)this.findViewById(R.id.bitmapImageView02);
//Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.moto);
//myImageView.setImageResource(R.drawable.moto);
Resources r=getResources();
Drawable d=r.getDrawable(R.drawable.moto);
if(null==d)
Log.d("drawable is null", null);
myImageView.setImageDrawable(d);
}}