Сделать отзывчивые рамки Xamarin формы - PullRequest
0 голосов
/ 30 января 2020

Я пытался сделать репрессивный в Xamarin Forms. Но не повезло. Это моя попытка.

<StackLayout Spacing="0" Padding="20">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="10"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>

        <Label x:Name="pol1" Text="some text" FontSize="Title" Grid.Row="1"/>
        <Frame BackgroundColor="Gray" Grid.Row="2" HasShadow="True" CornerRadius="10">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="200"/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <StackLayout Spacing="0">
                    <Label Text="some text" Grid.Row="2"/>
                    <Label Text="some text" Grid.Row="3"/>
                    <Label Text="some text" Grid.Row="4"/>
                    <Label Text="some text some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="5"/>
                    <Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
                    <Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
                </StackLayout>
            </Grid>
        </Frame>
    </Grid>
</StackLayout> 

enter image description here

Но кадр не масштабировать до текста. Я хочу сделать его масштабированным до конца текста.

1 Ответ

1 голос
/ 30 января 2020

Проблема с использованием StackLayout и индексацией здесь. В этом случае родительский макет не сможет правильно измерить размер. Я удалил ненужные StackLayouts, чтобы оптимизировать его. Теперь я могу получить желаемый результат с помощью приведенного ниже кода.

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="10"/>
        <RowDefinition Height="40"/>
    </Grid.RowDefinitions>

    <Label x:Name="pol1" Text="some text" FontSize="Title" Grid.Row="1"/>
    <Frame BackgroundColor="Gray" Grid.Row="2" HasShadow="True" CornerRadius="10">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="20"/>
                <RowDefinition Height="20"/>
                <RowDefinition Height="200"/>
                <RowDefinition Height="20"/>
                <RowDefinition Height="5"/>
                <RowDefinition Height="5"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <StackLayout Spacing="0">
                <Label Text="some text" Grid.Row="2"/>
                <Label Text="some text" Grid.Row="3"/>
                <Label Text="some text" Grid.Row="4"/>
                <Label Text="some text some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="5"/>
                <Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
                <Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
            </StackLayout>
        </Grid>
    </Frame>
</Grid>

Я получил следующий вывод. Я надеюсь, что это поможет вам.

Responsive frame

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...