解决方案 »

  1.   

    myImageView = (ImageView) this.findViewById(R.id.bitmapImageView02);
    myImageView.setImageResource(R.drawable.moto);
      

  2.   

    myImageView=(ImageView)findViewById(R.id.bitmapImageView02);
            Resources r=getResources();
            Drawable d=r.getDrawable(R.drawable.g1);
            myImageView.setImageDrawable(d);
    我把你的代码拷来试了下两个都显示第一张图都没问题
    R.drawable.moto
    是不是这张图有问题或者你没放到资源文件夹下
      

  3.   

    图片还是没有显示。
    图片是在C盘随便搜的。png,jpg格式的都不行。
      

  4.   

    写错了,应该是imageview.setBitmap吧,语法就有错误
      

  5.   

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.moto);
    myImageView.setImageBitmap(bitmap);
      

  6.   

    你可以看下你那个Drawable对象是不是为null,还有看下你启动的是不是这个activity
      

  7.   

    你可以看下你那个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对象是不是为空?
      

  8.   

    你可以看下你那个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>
      

  9.   

    你可以看下你那个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>
    判断下打印就知道了撒
      

  10.   

    你的moto是什么格式的?bmp?moto是jpg格式的,g1是png格式的。
      

  11.   

    你可以看下你那个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没有。
      

  12.   

    你的moto是什么格式的?bmp?moto是jpg格式的,g1是png格式的。
    不应该有没问题的啊,你把private ImageView myImageView;改成private ImageView myImageView=null;试试
      

  13.   

    你的moto是什么格式的?bmp?moto是jpg格式的,g1是png格式的。
    不应该有没问题的啊,你把private ImageView myImageView;改成private ImageView myImageView=null;试试还是没显示
      

  14.   

    重新建了工程,把之前的核心代码粘贴进去就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);
    }}