Difficulty with listview layout on Xamarin.Forms

Asked

Viewed 798 times

0

See this image

inserir a descrição da imagem aqui

My layout is broken. See that the client name is: Sebastiao Loureiro de Almeida and in the listview appears Sebastiao and it is noticed that the rest of the name gets further down, appearing only the "tip of the iceberg" of the name. My difficulty is in increasing the size of the cell or a horizontal scroll. I tried to make a scroll, putting all stacklayout inside, but it didn’t work. See the mainpage shampoo:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Autorizador"
             x:Class="Autorizador.MainPage">

    <StackLayout Orientation="Vertical">
        <StackLayout Padding="5,5,0,0">
            <Label Text="Adicionar um Produto" TextColor="Green" />
        </StackLayout>
        <StackLayout Padding="10,0,10,0">
            <Label x:Name="txtNome" Text="Cliente" HorizontalOptions="Start" 
                    VerticalOptions="StartAndExpand" HeightRequest="20" WidthRequest="300" FontSize="Small"/>
            <Label x:Name="txtCategoria" Text="Vendedor" HorizontalOptions="Start" VerticalOptions="StartAndExpand"
                   HeightRequest="20" WidthRequest="300" FontSize="Small"/>
            <Label x:Name="txtPreco" Text="Juros" HorizontalOptions="Start" VerticalOptions="StartAndExpand" 
                    HeightRequest="20" WidthRequest="300" FontSize="Small" />
            <!--<Button HorizontalOptions="FillAndExpand" VerticalOptions="StartAndExpand" HeightRequest="40" Text="Adicionar/Atualizar Produto" 
                    Clicked="btnAdicionar_Clicked" FontSize="Small"/>-->
        </StackLayout>
        <ScrollView HorizontalOptions="FillAndExpand">
            <StackLayout Orientation="Vertical" Padding="10,5,10,0">
                <ListView x:Name="listaLibera" ItemSelected="listaLibera_ItemSelected" BackgroundColor="Aqua" SeparatorColor="Blue">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <ViewCell>
                                <!--<ViewCell.ContextActions>
                                    <MenuItem Clicked="OnAtualizar" CommandParameter="{Binding .}" Text="Atualizar" />
                                    <MenuItem Clicked="OnDeletar" CommandParameter="{Binding .}" Text="Deletar" IsDestructive="True" />
                                </ViewCell.ContextActions>-->
                                <StackLayout Padding="10,10" Orientation="Horizontal" HorizontalOptions="StartAndExpand" VerticalOptions="StartAndExpand">
                                    <Label Text="{Binding Cliente}" HorizontalOptions="StartAndExpand"/>
                                    <Label Text="{Binding Vendedor}" TextColor="Blue" HorizontalOptions="Center"/>
                                    <Label Text="{Binding Juros}" HorizontalOptions="End"/>
                                    <Label Text="{Binding Filial}" HorizontalOptions="End" />
                                </StackLayout>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </StackLayout>
        </ScrollView>
    </StackLayout>
</ContentPage>

The C# of Mainpage

public partial class MainPage : ContentPage
    {
        DataService dataService;
        List<Liberacao> libera;
        public MainPage()
        {
            InitializeComponent();
            dataService = new DataService();
            AtualizaDados();
        }


        async void AtualizaDados()
        {
            libera = await dataService.GetLiberaAsync();
            listaLibera.ItemsSource = libera.OrderBy(item => item.Cliente).ToList();
        }

        private bool Valida()
        {
            if (string.IsNullOrEmpty(txtNome.Text) && string.IsNullOrEmpty(txtCategoria.Text) && string.IsNullOrEmpty(txtPreco.Text))
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        private void listaLibera_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var libera = e.SelectedItem as Liberacao;

            txtNome.Text = "Cliente: " + libera.Cliente;
            txtCategoria.Text = "Vendedor: " + libera.Vendedor;
            txtPreco.Text = "Juros: " + libera.Juros.ToString();
        }
    }

1 answer

1


  • Armindo, ok, appeared, but I have the Interest column that the 2.5 was below each other, IE, It has to increase horizontally the columns? If there’s another question I’ll ask another.

  • Appendage WidthRequest="40" Label interest and see if it suits you. Change the value 40 as your need. Anyway, I believe that 4 columns is not the ideal layout.

  • I went up to 240 and I realized that it seems to have a limit, I mean, it doesn’t automatically create a scroll, so no matter how much I turn it up, it feels like it shoots at a maximum and no matter how much I change the value to more, it’s still the same size.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.