2012-08-27 4 views
0

이미지가 TabIndecator로 설정된 탭이있는 응용 프로그램이 있습니다. URL에서 이미지를 가져 와서 특정 탭에 대해 지정된 URL로 TabIndecator 이미지를 설정하려고합니다. 그렇게 할 방법이 있습니까? ImageView를 가져 와서 TabIndecator로 설정할 수 있습니까?URL에서 탭 아이콘 이미지 설정

답변

0

URL에서 이미지를 가져 와서 해당 특정 탭에 대해 지정된 URL로 TabIndecator 이미지를 설정하고 싶습니다. 그렇게 할 방법이 있습니까?

없음 직접, 당신은 Bitmap로 이미지를 장치로 다운로드합니다 BitmapDrawable에 포장하고,

가 나는 이미지 뷰를 취할 수 TabSpect.setIndicator()로 설정하고 TabIndecator로 설정해야 ?

확실히, TabSpec.setIndicator()은 선택하면 인수로 View을 취할 수 있습니다.

0

이 방법을 사용하면 이미지의 URL에서 로컬 비트 맵을 가져올 수 있습니다. 내 의견은 스페인어로되어 있지만이 예제가 유용 할 것으로 기대합니다.

tabHost.newTabSpec("TODO").setIndicator("TODO", TODO).setContent(TODO); 
하십시오 AsyncTask를에서 실행해야하거나 (안 UI 스레드에서)과 유사합니다, 당신은이 비트 맵을 포장과 함께 사용하기 위해 BitmapDrawable을 다음

private static final int IO_BUFFER_SIZE = 8 * 1024; 
private static final int MINIMO_TAM = 10; 
public static final int MAXIMO_TAM = 640; 

public static Bitmap loadRemoteImage(CharSequence urlImagen) { 
    if (null == urlImagen) { 
     return null; 
    } 

    Bitmap bm = null; 
    InputStream is = null; 
    BufferedInputStream bis = null; 

    DefaultHttpClient httpclient = new DefaultHttpClient(); 
    httpclient.addRequestInterceptor(new GzipHttpRequestInterceptor()); 
    httpclient.addResponseInterceptor(new GzipHttpResponseInterceptor()); 

    try { 
     String urlSinEspacios = urlImagen.toString().replace(" ", "+"); 

     // Hacer la llamada 
     HttpGet httpget = new HttpGet(urlSinEspacios); 
     HttpEntity entity = httpclient.execute(httpget).getEntity(); 

     is = entity.getContent(); 
     bis = new BufferedInputStream(is, IO_BUFFER_SIZE); 
     //Obtener solo el tamaño 
     BitmapFactory.Options o = new BitmapFactory.Options(); 
     o.inJustDecodeBounds = true; 
     BitmapFactory.decodeStream(bis, null, o); 
     try { 
      bis.close(); 
      is.close(); 
     } catch (Exception e) { 
     } 

     //Calcular mejor escala 
     int scale = 1; 
     if (o.outHeight > MAXIMO_TAM || o.outWidth > MAXIMO_TAM) { 
      scale = (int) Math.pow(2, (int) Math.round(Math.log(MAXIMO_TAM/(double) Math.max(o.outHeight, o.outWidth))/Math.log(0.5))); 
     } 

     //Descargar el real 
     entity = httpclient.execute(httpget).getEntity(); 
     is = entity.getContent(); 
     bis = new BufferedInputStream(is, IO_BUFFER_SIZE); 

     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inTempStorage = new byte[16 * 1024]; 
     options.inSampleSize = scale; 
     bm = BitmapFactory.decodeStream(bis, null, options); 
     // Finalizado 
     httpclient.getConnectionManager().shutdown(); 
    } catch (Exception e) { 

     bm = null; 
    } finally { 
     try { 
      bis.close(); 
      is.close(); 
      // Finalizado 
      httpclient.getConnectionManager().shutdown(); 
     } catch (Exception e) { 
     } 
    } 

    return bm; 
} 

사용할 수 있습니다