Reputation: 49
Following steps:
I create dynamically an ImageView and set it to a bitmap that I have downloaded from server previously. The image is display small as a thumbnail by scaling it down using setLayoutParams without changing its real size. I have a horizontal LinearLayout in my main XML layout file on top of the display that gets populated with such thumbnails. Just imagine a row of thumbnails on top of the display. This works!
In the main XML layout file I have a bigger ImageView below the LinearLayout (as described above) that should show the big version of the thumbnail that I click. So somehow I must manage to assign the bitmap in the thumbnail ImageView to the bigger ImageView. It is not possible to simply to this: bigImageView = imageViewArray[i];
Can you please let me know how this assignment can be done?
Here is the main XML layout:
<LinearLayout 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"
android:orientation="vertical"
tools:context=".GalleryWithBaseadapter"
android:background="#000000">
<HorizontalScrollView
android:id="@+id/horizontalContainer"
android:background="#000000"
android:layout_width="wrap_content"
android:layout_height="120dp">
<LinearLayout
android:orientation="horizontal"
android:id="@+id/imgLinearLayout"
android:background="#000000"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="match_parent">
</LinearLayout>
</HorizontalScrollView>
<ProgressBar
android:id="@+id/myProgressBar"
android:visibility="visible"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:text="Click Me"
android:onClick="onClickButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/bigImage"
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Thank you for advice!
Upvotes: 0
Views: 619
Reputation: 312
Try this:
bigImageView.setImageDrawable(imageViewArray[i].getDrawable());
By the way you should set the large image from the file source and load small scaled versions of the images into your thumbnail list to avoid memory problems.
Upvotes: 2
Reputation: 7082
Try this:
ImageView bigImage = ...
ImageView[] smallImages = ...
public void setSmallToBig(int positionInSmallArray){
Drawable d = smallImages[positionInSmallArray].getDrawable();
bigImage.setDrawableImage(d);
}
Upvotes: 1