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!
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.
Try this:
ImageView bigImage = ...
ImageView[] smallImages = ...
public void setSmallToBig(int positionInSmallArray){
Drawable d = smallImages[positionInSmallArray].getDrawable();
bigImage.setDrawableImage(d);
}
Related
I am using xamarin android to make a android app in which i am using cardview with recycler view.
Problem
Image height is exceeding the wrap content of the text.
What is Want
I want the image size to be the size covered by text.
What I Have Tried:
I have tried setting image as a background of the linearlayout but it sets the height of the layout itself much greater than shown in images below.
i have tried setting this in framelayout but it gives same result as below
Details about the images
numbers are provided with the instance of the card view in
1: image the image source height is increasing the view height
2: this image is setted perfectly because the original image height resolution is low and the image is stretched to view
3: again image height resolution is high so the view is extended by image
4,5 cardview without image
My Code:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/cardView"
app:cardBackgroundColor="#android:color/transparent">
<ImageView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:id="#+id/cardImage"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/templateLayout"
>
<TextView
android:text="Title:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:id="#+id/listTitle"/>
<TextView
android:text="Start Time:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:id="#+id/listSTime"/>
<TextView
android:text="End Time:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:id="#+id/listFTime"/>
<TextView
android:text="Description:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:id="#+id/listDescription"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
Images:
Add the following fields to ImageView
android:scaleType="centerCrop"
android:adjustViewBounds="true"
you can change the imageView attributes to android:scaleType="centreCrop" and change the height to wrap content. you are matching it to parent in you case,its the card view. Whereas, textview is in a linearlayout.
Orelse you can move ImageView to same linearLayout of the textView
how to make single view with multiple imageviews?
I know this is just a simple question but its puzzle for me ...
problem
there are 4 images one for whole background image ,2nd is transparent heart and 3 image is to put in heart and 4 image is a shadow image of heart but how to manage these four images in a single view(any layout)....
Any help would be appreciated see link to see my desired output
link to see photo
update
<RelativeLayout
android:id="#+id/relativelayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/hv_effect"
android:layout_below="#+id/effect_hedaer_toolbar"
android:background="#drawable/home_wall"
android:weightSum="1">
<FrameLayout
android:id="#+id/relative_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center|center_vertical"
android:padding="50dp">
<ImageView
android:id="#+id/iv_effect_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<ImageView
android:id="#+id/iv_effect_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center|center_vertical"
android:adjustViewBounds="false"
android:scaleType="fitXY"
android:src="#drawable/pip" />
</FrameLayout>
</RelativeLayout>
i have used relative for background image and framelayout to show two imageview to show one is for to show lamp image and second two move as background (user selected image)....
problem:
problem is user selected image must be move only inside lamp.
update read comments to get answer
I'm pretty sure you can do it simply by using a RelativeLayout. The transparent image should be the last one in the layout, example:
<RelativeLayout 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">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/background_image"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/transparent_image"/>
</RelativeLayout>
I added a fragment with an ImageView, which is a PNG image, and a TextView just below it.
The fragment is showing fine but when I rotate the screen the image will take most of the screen and the TextView is partially cut.
Here's the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/shopping_cart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/shopping_cart" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_below="#id/shopping_cart"
android:text="#string/no_data"
android:gravity="center"/>
</RelativeLayout>
I'm trying to find a way to resize the image in order to show both image and text in the screen
try using a scroll-view as the root element if u want to retain the same image size rather than resizing the image. Here's a small snippet -
<ScrollView
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:fillViewport="true">
<RelativeLayout
android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
(all your view elements)
</RelativeLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/text_image_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
(Enter view here)
</LinearLayout>
Alright, so firstly ensure that you have the image for the ImageView in all densities. I would suggest that you use this attribute in your ImageView code:
https://developer.android.com/reference/android/widget/ImageView.ScaleType.html
The scale type defines how your image should scale according to the view. I faced a similar issue once, and i was able to solve it using this. Having said that, i have not seen the image you are using, so i cannot be very sure of it. But, i would say that you use:
android:scaleType="centerCrop"
you can find the definition of the attribute on the link provided above. Also, i do not know what devices you are targeting for your app, but its always good to keep views inside a scroll view so that they are visible even on a smaller screen.
Give it a try, if not by centerCrop, then maybe by some other attribute.
Cheers!!
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/shopping_text"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/no_data"/>
<ImageView
android:id="#+id/shopping_cart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/shopping_text"
android:src="#drawable/shopping_cart"/>
</RelativeLayout>
Hey I begin my adventure with Android and I can't solve one problem.
I am loading pictures from web server using Universal Image Loader. I put them into Relative Layouts which is located in ListView. The effect that I want to achieve, is that pictures are displayed on the entire screen with full width and height with a small box at the bottom.
In the IDE preview, everything looks ok:
But on my phone loaded images look like that. I want them to be displayed with full height. It is necessary to use programming functions to achive it?
Loading images:
imageLoader.displayImage(
wallpapers.get(position).getSrcUrl()//the drawable
, currentWallpaperViewHolder.imageViewWallpaper//the image view
, imageLoaderOptions);//the display options
return itemView;
List view:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ListView
android:id="#+id/WallpapersListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Image view:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/wallpaper_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/test"
/>
<TextView
android:id="#+id/wallpaper_date_for_use"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:padding="12dip"
android:background="#AA000000"
android:textColor="#ffffffff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textStyle="bold"
android:text="Date of use" />
</RelativeLayout>
It's probably because you have a RelativeLayout as your root view. Try wrapping the outside RelativeLayout in a LinearLayout.
You can do this,
Get the device height.
And then set imageView height programatically as the device height.
Well I have to fit one ImageView inside another one. It is smaller and has to be exactly at the center. I have both images scaled for different screen resolutions but I can test only on one phone and I am wondering if I set the second image's height and width with dpi to fit my screen resolution will it be perfectly matched on all screens or is there any property in Android aside from setting the height and width that will automatically center one ImageView inside of other ImageView?
Edit: It's in RelativeLayout and the ImageViews are at the top left so I haven't added anything specific to the because they by default are there.
Edit2: Well changing the first ImageView to be RelativeLayout helps center the second image inside of it but then the RelativeLayout grows too big and enlarges the image that is background. Is there a way to make the RelativeLayout be as big as its background?
try this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="250dp"
android:layout_height="250dp" >
<ImageView
android:id="#+id/base"
android:layout_height="250dp"
android:layout_width="250dp"
android:src="#drawable/home"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<ImageView
android:id="#+id/center"
android:layout_height="150dp"
android:layout_width="150dp"
android:src="#drawable/home"
android:layout_centerInParent="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</RelativeLayout>
You cannot put an imageView inside another. Hope the following code will be helpful for you.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_image"
android:gravity="center" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image_on_center" />
</LinearLayout>
Use RelativeLayout and then use android:layout_centerInParent="true" remember the order you add the ImageViews will decide what is on top :)
Try this:
android:layout_gravity="center"