Scale image to fit inside imageview with xamarin glide library - c#

I'm having trouble getting images from certain sources to load in my recycler view. Inside my view for the rows is this
<ImageView
android:id="#+id/image1"
android:layout_width="match_parent"
android:layout_height="230dp"
android:scaleType="centerCrop" />
Most images seem to load fine here, but when I load an image from the user's device from uri it seems to not show up in this view. I did notice that if I change the height to something larger the image does show. Here is how I'm loading the image inside my recycler view adapater.
var uri = Android.Net.Uri.Parse(_recipes[position].ImageUrl);
Glide.With(_context)
.Load(uri)
.DontAnimate()
.Into(vh.RecipeImage);
When the image doesn't show its just blank. Is this something wrong with scaling? How do I get the image to fit properly?

Related

How can I rotate a text properly in xamarin android? (execute rotation first)

How can I rotate a text in c# android xamarin? If I use rotate: this happens
I did read some similar question that maybe overriding textview helps, but how can I do this?
The problem is as you can see the in the posted image the width and height stays the same so it's still using the same space(this is visible in visual studio here) however the rotated element occupies less space(layout_rowweight is not relative) and the text getting cut off.
What I want to achieve is to use layout_rowweight(or sg similar) to fill the fullscreen relatively. Do I have to override textview somehow?
Basically what I want is to rotate execute first then every other property relative to the new rotation.
<TextView
android:text="Placeholder 101"
android:textSize="25sp"
android:background="#F44336"
android:layout_columnSpan="1"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_rowSpan="1"
android:textDirection="?android:attr/windowTransitionBackgroundFadeDuration"
android:id="#+id/textViewx1"
android:rotation="90" />

Xamarin Android - Gif in WebView is displayed blank

I got an issue while trying to display a gif for my UI.
When the app is launched, the .gif file is correctly loaded (if i change the path, a loading error occure) but the webView is displayed blank.
Android version : marshmallow 6.0 API lvl 23
the "ship_sea.gif" is currently located in Assets Folder, with "Android Asset" in build action.
the axml:
<WebView
android:id="#+id/myWebGIF"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginTop="50dp"
android:layout_marginLeft="50dp" />
the .cs :
WebView webGif = FindViewById<WebView>(Resource.Id.myWebGIF);
webGif.LoadUrl(string.Format("file:///android_asset/ship_sea.gif"));
Why is this not working? It is really simple and I can't figure out what is the problem.
Could it be the device as this post suggests (NVIDIA Shield Tablet K1)?
Ok guys, here is the answer :
Be sure that your canvas is the same size as your gif.
In my case, i had a particular large gif, and the only part rendered in my canvas was the top-left (a blank part).
The default background color for a webView is white, so it resulted in a blank view.
Problem solved : there was no error, just wrong interpretation of the problem.

Replace an image when clicked

Not sure if the title makes any sense.
In my WPF application I would like the window to contain a small image, icon size. When the user clicks on the image another one simply replaces it, that holds the same dimensions.
I have all the images loaded into my project for C#/WPF. (By the way there are 3 images)
What I have been trying:
I tried changing the opacity in the code-behind to make one image
have full opacity and the others have no opacity. Didn't work as the
first toggle would strangely make all images disappear.
I also tried dynamically changing the image source in the code-behind. I
used if statements and a field to determine what image to switch
the source to. Code being:
if (toggle == 1)
{
thebutton.Source = new BitmapImage(new Uri(#"/images/icon2.png", UriKind.Relative));
toggle = 2;
}
Also did not work (made it blank, rather than switching to another image) but I feel like there is an obvious way I'm not seeing.
What I initially wanted to do was simply (like in graphics programs) raise and lower the images to the top and bottom to determine which ones the user should see. All that matters is the visual. The user clicks image 1, image 1 disappears and image 2 appears in its place, and so on for image 3.
Set the Build Action of the image files to Resource, and load them by Resource File Pack URIs:
thebutton.Source = new BitmapImage(new Uri("pack://application:,,,/images/icon2.png"));

Image shrinking in a label of c# win forms

I am designing a c# .NET 4.5 win form.While inserting an image in a label, the image is behaving differently.I have two labels and i insert 2 different image in them.In the first one, i am setting image using an Image property and in the second one, i am just using the ImageList.Now the funny thing is that for the second label, its image is shrinking while for the first label its not. Why is it happening so??Please advise. Image is attached herewith for better understanding:
In the image, you can see that image of first label is showing correctly, while that of second label not
The issue is that the Image and ImageList properties work pretty differently. While for the Image, it will display the image as it is, ImageList has a property called ImageSize. This property affects the size of the stored images in the Label ImageList at compile time such that all images in the ImageList will have the size of ImageSize in the runtime.
Your image shrinking in when you use ImageList is likely caused by this. The default value of ImageSize is 16x16.
And you also cannot change the ImageSize at runtime, since it will be like replacing the list, all images will not be displayed(!).
So, if you display your images using ImageList, all your images must be of the same size. Or else, you have to put your images in the Resources.resx such that the image size will not be changed and somehow access to the images there at run time.

ImageButton in Xamarin Studio

I am using the Xamarin Studio. I have a problem when I try to use an ImageButton. The problem is that whatever image I use it doesn't fit with the button. The image is too big or too small. Even if I try to resize the button, the image doesn't stretch to be at the same size with the button.
Couple of questions to start with - which version of Xam.Android are you using (stable, beta, alpha) and can you post the code you're currently using?
This solution may help you in any case : Fit Image in ImageButton in Android
If you need the image to stretch use scaleType attribute with fitXY like so:
try different settings from the visual designer to see the effects
<ImageButton
android:src="#android:drawable/someDrawable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageButton1"
android:scaleType="fitXY" />

Categories