Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How to fit the height of CollectionView when it is wrapped by ScrollView?

$
0
0

Hi to everyone!
I do not know if is a problem or a misunderstanding by me (maybe the second one) but I can not success to set any height size to my CollectionView.

I am starting to use Xamarin and I was trying to use the CollectionView object when I realized that the height of this View is very large (and other View Objects had an addecuate size, for example Label Views).
The height is more or less like the height Page.
Firstly I think that was a problem with the inside objects. I tried with strings and custom objects without success.
After a lot of tests, I tried with an empty CollectionView (with the BackgroundColor set in LightBlue) and I realized that my problem is not in the collectionView objects, but is in the CollectionView object itself.
When I was trying to reproduce the problem to publish it here I realized that the CollectionView was fitting its own size to the page size (the height is still very big but less than the height Page).
So, finally, I checked my code and found that the CollectionView is inside a StackLayout and this StackLayout is in a ScrollView.
I mean:

    <ScrollView>
       <StackLayout>
          <CollectionView>
          </CollectionView>
       </StackLayout>        
    </ScrollView>

When I wrap the StackLayout in a ScrollView, the CollectionView height increase (I didn't measure it, but the height is more or less like the height page).

This height is very large and I didn't find an option to change its height.

I am using the latest stable version of Xamarin (3.6.0.344457). But I also checked the latest preliminar version (4.0.0.394984-pre) without success.
To test the program I am using an emulator with Android 9.0 (Api 28) and my own smartphone (Nexus 5X with Android 8.1, Api 27).

To reproduce the problem I created a new Mobile Application (Xamarin.Forms) project, select a Shell template and, in ItemDetailPage.xaml, I added the ScrollView, two labels and the CollectionView.
This is the full code of ItemDetailPage.xaml with my own modifications:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http: //xamarin.com/schemas/2014/forms"<!-- Here I added a space between "http:" and "//" because I can not publish urls in the forum-->
             xmlns:x="http: //schemas.microsoft.com/winfx/2009/xaml"<!-- The same here-->
             x:Class="XamarinTest.Views.ItemDetailPage"
             Title="{Binding Title}">

    <ScrollView>
        <StackLayout Spacing="20" Padding="15">
            <Label Text="Text:" FontSize="Medium" />
            <Label Text="{Binding Item.Text}" FontSize="Small"/>
            <Label Text="Description:" FontSize="Medium" />
            <Label Text="{Binding Item.Description}" FontSize="Small"/>

            <Label Text="CollectionView:"></Label>
            <CollectionView BackgroundColor="LightBlue">

            </CollectionView>
            <Label Text="End CollectionView"></Label>
        </StackLayout>        
    </ScrollView>

</ContentPage>

I only want a CollectionView that it only has the necessary height, the enough to wrap it's own children.

Thanks in advance!


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>