![](/img/trans.png)
[英]In android, how can I put tabs in a view containing an image on top?
[英]How can I download and put an image in a view in Android
我使用 API (...) 我收到一個包含 png 的 url,但我無法顯示圖片。
我必須下載圖片,並顯示它。 我做了一個手勢來請求另一張圖片,所以當用戶詢問最新的圖片時,我必須刪除舊的圖片(當他在圖片上做手勢時)
所以,我有一種下載並顯示圖片的方法(但屏幕仍然是黑色的......):
private void downloadImage() {
Bitmap bitmap = null;
try {
URL urlImage = new URL("http://www.google.fr/intl/en_com/images/srpr/logo1w.png");
HttpURLConnection connection = (HttpURLConnection) urlImage.openConnection();
InputStream inputStream = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
Log.v("", "is showed");
image.setImageBitmap(bitmap);
Log.v("", "isn't");
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();}
}
在 onLoad 中,我放了
setContentView(R.layout.secondtab);
圖像 = (ImageView)findViewById(R.id.ivImage);
我在@Override 之前聲明了 ImageView 圖像。
在 xml 中是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<android.gesture.GestureOverlayView
android:id="@+id/gestures" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1.0"
android:eventsInterceptionEnabled="true" android:gestureStrokeType="single"
android:gestureColor="#00FFFFFF"/>
<ImageView
android:id="@+id/ivImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical"
/>
感謝您的幫助:-)
也許試試image.postInvalidate()
? 如果您在 UI 線程上運行所有這些,或者只是使其無效。
我的錯誤是同一行有兩次:
setContentView(R.layout.secondtab);
現在它正在運行,我只需要調整它的大小!
感謝 StackOverFlow!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.