ImageButton in Xamarin Studio - c#

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" />

Related

VerticalSlider for Xamarin.Android

I am using the Slider (https://developer.android.com/reference/com/google/android/material/slider/Slider) in a Xamarin.Android app. However, I need a slider that is vertical, and there does not seem to be a VerticalSlider available. Rotating the Slider makes it very hard to do layout for anything that is not a fixed size (which is almost everything). Are there any good View(s) or relatively simple workarounds available that allow functionality similar to the Slider? I prefer to avoid most third-party downloads for this type of thing, and would prefer that it be a NuGet package if that is my only choice. Any suggestions?
There is no out-of-the-box verticalslider for you.
I think the common method is set property Rotation for the material Slider.
You can put the Slider into a Frame.
Please refer to the following code:
<com.google.android.material.slider.Slider
android:id="#+id/sldPenWidth"
android:layout_width="200dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:rotation="270"
android:value="1"
android:valueFrom="0.1"
android:valueTo="10" />
</FrameLayout>

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" />

Scale image to fit inside imageview with xamarin glide library

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?

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.

Office RibbonUI ApplicationMenu Icon

I'm having weird issues with the LargeImageSource for the Application menu (using Office2007Blue theme)
My image is 48x48 but it appears to be scaling down to 10x10. It's not using SmallImageSource at all.
<r:Ribbon.ApplicationMenu>
<r:RibbonApplicationMenu>
<r:RibbonApplicationMenu.Command>
<r:RibbonCommand
SmallImageSource="images/icon.png"
LargeImageSource="images/icon.png"
ToolTipTitle="Application Menu"
ToolTipDescription="Click here to open files or close the application." />
</r:RibbonApplicationMenu.Command>
<r:RibbonApplicationMenuItem>
<r:RibbonApplicationMenuItem.Command>
<r:RibbonCommand
LabelTitle="_Close"
LabelDescription="Close the Application"
/>
</r:RibbonApplicationMenuItem.Command>
</r:RibbonApplicationMenuItem>
</r:RibbonApplicationMenu>
</r:Ribbon.ApplicationMenu>
Changing the image's printed dimensions fixed it. The button doesn't look at the pixel dimensions.
The WPF Ribbon is full of bugs. This one in particular is because the SmallImageSource Image is hardcoded to 16x16 in the RibbonApplicationMenu's control template. LargeImageSource isn't even used anywhere in the default theme.

Categories