解决方案 »
- 菜鸟请教,关于eclipse中从一个activity跳转到另一个activity运行unfortunately activity has stopped时提示
- android导入现存数据库出IO异常
- 直接插的内存卡,为什么读不出来内容
- 判断GPS是否开启问题
- 修改spinner点击后样式的疑问--android,谢谢指导~~
- android socket 从客户端到服务器传图片的奇葩现象,求大神指导下
- 新人问一下移动支付使用的问题。
- 关于对话框Builder的问题
- 关于android结束应用监听
- android应用的界面设计主流是什么?是布局还是HTML
- 将原始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);
}}