我的问题是我想在屏幕上一次显示一张图像,并且每天我的图像都会发生变化。我正在使用 imageView,但它显示 notification.xml 的所有图像。我搜索了很多,我认为我错过了一些简单的事情。请帮忙。
Notification.java 是:
package com.example.customcalendarandroid;
import java.io.File;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.app.Activity;
import android.graphics.drawable.Drawable;
public class NotificationView extends Activity{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.notification);
//setContentView(R.layout.newxml);
int i=10;
if(i==10){
ImageView imgView = (ImageView) findViewById(R.id.ekadashi_name2);
imgView.setImageResource(R.drawable.prabhu2);
}else
{
ImageView imgView = (ImageView) findViewById(R.id.ekadashi_name3);
imgView.setImageResource(R.drawable.prabhu3);
}
}
and
notification.xml is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/ekadashi_name"
android:layout_width="match_parent"
android:layout_height="20sp"
android:src="@drawable/krishna" />
<ImageView
android:id="@+id/ekadashi_name1"
android:layout_width="match_parent"
android:layout_height="20sp"
android:src="@drawable/prabhupada" />
<ImageView
android:id="@+id/ekadashi_name2"
android:layout_width="match_parent"
android:layout_height="20sp"
android:src="@drawable/prabhu2" />
<ImageView
android:id="@+id/ekadashi_name3"
android:layout_width="match_parent"
android:layout_height="20sp"
android:src="@drawable/prabhu3" />
<ImageView
android:id="@+id/ekadashi_name4"
android:layout_width="match_parent"
android:layout_height="20sp"
android:src="@drawable/prabhu4" />
<ImageView
android:id="@+id/ekadashi_name5"
android:layout_width="match_parent"
android:layout_height="20sp"
android:src="@drawable/prabhu5" />
<ImageView
android:id="@+id/ekadashi_name6"
android:layout_width="match_parent"
android:layout_height="20sp"
android:src="@drawable/prabhu6" />
<ImageView
android:id="@+id/ekadashi_name"
android:layout_width="match_parent"
android:layout_height="20sp"
android:src="@drawable/prabhupada1" />
</LinearLayout>
最佳答案
您可以使用图像数组 喜欢
private int[] imagesArray = {
R.drawable.img_00,
R.drawable.img_01,
R.drawable.img_02,
};
那么你可以这样做
Drawable d = getResources().getDrawable(imagesArray[i]);
yourImageView.setImageDrawable(d);
每次要加载图像时只需更改 int i 值即可
在 xml 中只保留一个可以工作的 ImageView ..u 为不同的图像保留不同的 ImageView
希望对你有帮助
关于java - 如何使用 imageView 一次显示一张图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24059099/