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?

Martin Žid
  • 289
  • 3
  • 18

2 Answers2

10

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

Gerald Versluis
  • 30,492
  • 6
  • 73
  • 100
  • 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. – R15 Oct 09 '18 at 14:29
  • What Xamarin.Forms version are you using? – Gerald Versluis Oct 09 '18 at 14:30
  • I am using Xamarin.Forms 3.2.0.871581. Shouldn't it work for me? – R15 Oct 09 '18 at 14:31
  • 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? – Gerald Versluis Oct 09 '18 at 14:33
  • 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. – R15 Oct 09 '18 at 14:38
  • 1
    I see, you're talking Android. We are talking iOS :) – Gerald Versluis Oct 09 '18 at 14:49
  • 1
    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! – Gerald Versluis Oct 09 '18 at 14:54
  • My problem occurred on the Xamarin.GTK, where neither of these solutions seem to work. But thank you for your tips. – Martin Žid Oct 10 '18 at 05:47
  • Ah! That is also a possibility there days ;-) Unfortunately I'm not able to test GTK right now – Gerald Versluis Oct 10 '18 at 06:19
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.

Spike433
  • 51
  • 4