Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing Activity Indicator in Xamarin Forms

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?

like image 758
Martin Žid Avatar asked Oct 09 '18 14:10

Martin Žid


People also ask

What is activity indicator in xamarin forms?

The Xamarin. Forms ActivityIndicator control displays an animation to show that the application is engaged in a lengthy activity. Unlike the ProgressBar , the ActivityIndicator gives no indication of progress. The ActivityIndicator inherits from View .


2 Answers

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

like image 171
Gerald Versluis Avatar answered Sep 23 '22 10:09

Gerald Versluis


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.

like image 36
Jura J Hlevnjak Avatar answered Sep 22 '22 10:09

Jura J Hlevnjak