80,350
社区成员
发帖
与我相关
我的任务
分享
<?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>
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);
}
}
<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);
}
}
<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对象是不是为空?[/quote]
晕,粘错了
<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>
[/quote]
判断下打印就知道了撒[/quote] Drawable d=r.getDrawable(R.drawable.moto);
if(null==d)
Log.d("drawable is null", null);
myImageView.setImageDrawable(d);
加了打印,logcat.txt没有。[quote=引用 18 楼 woaili03019 的回复:] [quote=引用 13 楼 u010119353 的回复:] Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.moto); myImageView.setImageBitmap(bitmap);
[quote=引用 13 楼 u010119353 的回复:] Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.moto); myImageView.setImageBitmap(bitmap);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.moto); myImageView.setImageBitmap(bitmap);
一张图片都没显示,是空白的。 [quote=引用 14 楼 mujunfengplay 的回复:] [quote=引用 11 楼 woaili03019 的回复:] [quote=引用 9 楼 mujunfengplay 的回复:] 我估计你上面的图片太大了 下面的显示不出来
<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对象是不是为空?[/quote]
晕,粘错了
<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>
[/quote]
判断下打印就知道了撒一张图片都没显示,是空白的。 [quote=引用 11 楼 woaili03019 的回复:] [quote=引用 9 楼 mujunfengplay 的回复:] 我估计你上面的图片太大了 下面的显示不出来
<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对象是不是为空?[/quote]
晕,粘错了
<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>
一张图片都没显示,是空白的。 [quote=引用 9 楼 mujunfengplay 的回复:] 我估计你上面的图片太大了 下面的显示不出来
<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对象是不是为空?一张图片都没显示,是空白的。 我估计你上面的图片太大了 下面的显示不出来
试试ICO?
我估计你上面的图片太大了 下面的显示不出来