package com.example.imagechange;
public class MainActivity extends Activity
{
ImageView imageView;
int []imageArray={R.drawable.a0,R.drawable.a1,R.drawable.a2,R.drawable.a3};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView)findViewById(R.id.imageView1);
final Handler handler = new Handler();
Runnable runnable = new Runnable()
{
int i=0;
public void run()
{
imageView.setImageResource(imageArray[i]);
i++;
if(i>imageArray.length-1)
{
i=0;
}
handler.postDelayed(this, 3000); //for interval...
}
};
handler.postDelayed(runnable, 1000); //for initial delay..
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
我的 ACTIVITY_MAIN :
<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" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="@string/app_name"
android:layout_marginTop="56dp"
android:src="@drawable/a0" />
</RelativeLayout>
所以在上面的代码中,我复制了drawable中的图像并定期更改它,但我需要url
从ImageView
.