MainActivity AppCompatActivity { (Bundle savedInstanceState) { .onCreate(savedInstanceState)setContentView(R.layout.)Image a=Image()Image.MyAsyncTask task=a.MyAsyncTask()task.execute()} (View view) { startActivity(Intent(Image.))} }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:onClick="loadimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="loading image"
/>
</LinearLayout>
Image Activity { ImageView ProgressBar String = (Bundle savedInstanceState) { .onCreate(savedInstanceState)setContentView(R.layout.)= (ImageView) findViewById(R.id.)= (ProgressBar) findViewById(R.id.)MyAsyncTask().execute()} MyAsyncTask AsyncTask<StringVoidBitmap> { () { .onPreExecute().setVisibility(View.)} (Bitmap bitmap) { .onPostExecute(bitmap).setVisibility(View.).setImageBitmap(bitmap)} Bitmap (String... params) { String url = params[]Bitmap bitmap = URLConnection connectionInputStream is{ connection = URL(url).openConnection()is = connection.getInputStream()BufferedInputStream bis = BufferedInputStream(is)bitmap = BitmapFactory.(bis)is.close()bis.close()} (IOException e) { e.printStackTrace()} bitmap} } }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>
蜂之谷
相关分类