【问题标题】:Button with image and text and text bellow the image, how?带有图片和文字的按钮以及图片下方的文字,怎么样?
【发布时间】:2017-12-12 18:53:19
【问题描述】:

第一次使用 xamarin 的跨平台应用程序,我正在 Visual Studio 2017 社区中使用 xamarin 表单。

我有一个带有图像和文本的按钮,但文本需要位于图像下方。当前文本显示在图像的左侧,我该怎么做?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;

namespace AppUnap
{
public class PPrincipal : ContentPage
{
    public PPrincipal()
    {
        Button btn1= new Button();
        btn1.Image = "notas.png";
        btn1.Text = "Calificaciones";
        btn1.HorizontalOptions = LayoutOptions.CenterAndExpand;

        Button btn2 = new Button();
        btn2.Image = "notas.png";
        btn2.Text = "Aula Virtual";
        btn2.HorizontalOptions = LayoutOptions.CenterAndExpand;

        Content = new StackLayout
        {
            Spacing = 0,
            VerticalOptions = LayoutOptions.CenterAndExpand,
            Children =
            {
            new StackLayout
            {
                Spacing = 0,
                Orientation = StackOrientation.Horizontal,
                Children =
                {                       
                    btn1,
                    btn2,
                }
            }
            }


        };
    }
}
}

【问题讨论】:

    标签: android button text xamarin.forms cross-platform


    【解决方案1】:

    您需要在按钮上使用 ContentLayout。

    这是我在 XAML 中使用的代码:

    <Button Command="{Binding MyCommand}" ContentLayout="Top,0" Text="mytext" Image="myimage.png" />
    

    顶部 = 图像的位置

    0 = 图片和文字之间的间距

    你应该很容易找到如何在 C# 中使用 ContentLayout

    【讨论】:

      【解决方案2】:

      为了获得上述结果,我使用了 ImageButtom,因为可以调整图像大小。我是这样弄的:

        <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
            <Label 
                  Text="{Binding CountryId}"
                  TextColor="{DynamicResource PrimaryDarkColor}"
                  FontFamily="MontSerratBold"
                  Margin="0, 0, 0, 10"
                  VerticalOptions="End"
                  HorizontalTextAlignment="Center" 
                  VerticalTextAlignment="End"/>
            <ImageButton 
                  Source="{Binding CountryUrl}"
                  HorizontalOptions="Center"
                  VerticalOptions="Start"
                  BackgroundColor="Transparent" 
                  Padding="0, 10, 0, 30"
                  HeightRequest="90"
                  Command="{Binding OpenPickerPopUp}"/>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-23
        • 2017-09-26
        • 1970-01-01
        • 2014-07-15
        相关资源
        最近更新 更多