Resizing Activity Indicator in Xamarin Forms
Asked Answered
P

2

6

I am trying to resize an ActivityIndicator (in Xamarin.Forms), but the Scale property does not work and the HeightRequest just crops the ActivityIndicator.

<StackLayout>
    <ActivityIndicator HorizontalOptions="Center" VerticalOptions="StartAndExpand" HeightRequest="20" IsRunning="True" />
</StackLayout>

This is the result.

enter image description here

Any suggestions on what I might be doing wrong?

Pozsony answered 9/10, 2018 at 14:8 Comment(0)
S
12

It seems sizing itself is not supported on the ActivityIndicator. In this case, scaling is your friend.

The cutting-off you see happening is because the ActivityIndicator is inside a StackLayout. Because of how a StackLayout works, it will only take up the space it needs. Since scaling doesn't necessarily make your ActivityIndicator bigger, you have two options:

  • Replace your StackLayout with a Grid

  • Give your ActivityIndicator a WidthRequest and HeightRequest that is big enough to keep your scaled ActivityIndicator

Note: Talking about iOS here. Width and height seem to work on Android

Sothena answered 9/10, 2018 at 14:21 Comment(9)
The xaml posted by Martin works fine for me, even I can increase or decrease height of indicator ActivityIndicator that adjust according. It means the issue should be in total xaml what Marin might have.Nola
What Xamarin.Forms version are you using?Sothena
I am using Xamarin.Forms 3.2.0.871581. Shouldn't it work for me?Nola
Hm no, I can't influence the width by using WidthRequest and HeightRequest. Do you have any code or maybe a sample repository to share?Sothena
In my xaml file I have exactly & only same code what Martin posted. I can change WidthRequest & HeightRequest of ActivityIndicator & those changes are immediately affecting to previewer window.Nola
I see, you're talking Android. We are talking iOS :)Sothena
O no! Don’t worry about it! I added a note to the answer for the future readers that it does work on Android. So nothing was wasted!Sothena
My problem occurred on the Xamarin.GTK, where neither of these solutions seem to work. But thank you for your tips.Bollard
Ah! That is also a possibility there days ;-) Unfortunately I'm not able to test GTK right nowSothena
E
4

Remove HeightRequest="20", it blocks your scale property.

Code should look like this

<ActivityIndicator HorizontalOptions="Center" VerticalOptions="StartAndExpand" Scale="2" IsRunning="True" />

Now, you can scale to whatever size you want.

Embank answered 8/9, 2021 at 16:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.