-1

我有一组按钮,我希望它们仅在加载图像时可见..并且要隐藏进度条,我该怎么做..无论何时使用 onPreExecute() 或编写

 buttonname.setVisibility(View.VISIBLE); 

在执行后它停止加载图像..这是我正在使用的..请帮帮我我被卡住了

    public class Main extends Activity{

    ImageView image,next,back;
    Button a;
    static int fullWidth;
    static int fullHeight;
     ProgressBar progressbar;
     Button setWallpaper;


     private class BackgroundTask extends AsyncTask <String, Void, Bitmap> {
            protected Bitmap doInBackground(String...url) {
                //--- download an image ---
               Bitmap bitmap = DownloadImage(url[0]);
                return bitmap;
            }
            protected void onPostExecute(Bitmap bitmap) {

                ImageView image = (ImageView) findViewById(R.id.imageView1);
                bitmaptwo=bitmap;
                image.setImageBitmap(bitmap);
                image.setScaleType(ScaleType.FIT_CENTER);


            }
        }
    private InputStream OpenHttpConnection(String urlString)
    throws IOException
    {InputStream in = null;
    int response= -1;
    URL url = new URL(urlString);
    URLConnection conn = url.openConnection();
   if (!(conn instanceof HttpURLConnection ))
   throw new IOException("Not an HTTP connection");
    try{
        HttpURLConnection httpConn = (HttpURLConnection) conn;
        httpConn.setAllowUserInteraction(false);
        httpConn.setInstanceFollowRedirects(true);
        httpConn.setRequestMethod("GET");
        httpConn.connect();
        response = httpConn.getResponseCode();
        if (response == HttpURLConnection.HTTP_OK){
            in = httpConn.getInputStream();
        }
        }
    catch (Exception ex)
    {
        throw new IOException("Error connecting");
    }
    return in;
    }
    private Bitmap DownloadImage(String URL)
    {
        Bitmap bitmap = null;
        InputStream in = null;
        try {
            in = OpenHttpConnection(URL);
            bitmap = BitmapFactory.decodeStream(in);
            in.close();
        }
        catch (IOException e1){
            Toast.makeText(this,e1.getLocalizedMessage(),
            Toast.LENGTH_LONG).show();

            e1.printStackTrace();
        }
        return bitmap;
    }
    public static Bitmap bitmaptwo;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        try
        {
        new BackgroundTask().execute("http://meluha.in/wp-content/uploads/1.jpg");
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }


        setWallpaper = (Button) findViewById(R.id.abcd);
        ImageView next = (ImageView) findViewById(R.id.next);
        ImageView back = (ImageView) findViewById(R.id.back);


        setWallpaper.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                WallpaperManager wManager;

                try {

                //  Bitmap bitmap = ((BitmapDrawable)imageView1.getDrawable()).getBitmap();
                    wManager = WallpaperManager.getInstance(getApplicationContext());
                    fullWidth = wManager.getDesiredMinimumWidth();
                    fullHeight = wManager.getDesiredMinimumHeight(); 
                    Bitmap bitmapResized = Bitmap.createScaledBitmap(bitmaptwo, fullWidth, fullHeight,true);
                    wManager.setBitmap(bitmapResized);


                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        });
}
}
4

1 回答 1

0

将此代码添加到您的onPostExecute方法中:

button1.setVisibility(View.VISIBLE);
button2.setVisibility(View.VISIBLE);
//....
progressbar.setVisibility(View.INVISIBLE);
于 2012-11-17T22:09:43.263 回答