android - 带有图像和文本的按钮以及图像下方的文本,如何?

标签 android button text xamarin.forms cross-platform

第一次使用 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,
                }
            }
            }


        };
    }
}
}

最佳答案

您需要在按钮上使用 ContentLayout。

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

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

顶部 = 图片的位置

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

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

关于android - 带有图像和文本的按钮以及图像下方的文本,如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44988312/

相关文章:

android - 如何从适用于 Android 的 Google Places GeoDataApi 解析地址(缺少地址组件)

android - 我的列表、 ScrollView 和按钮出错

c# - 如何以编程方式将按钮添加到 gridview 并将其分配给特定的代码隐藏函数?

android - 单击事件触发时如何确定 subview 的父级?

javascript - 在 node.js 退出之前写入 .txt 文件

android - 是否有其他解决方案而不是嵌套的 Recyclerview

javascript - 如何让 React Native 项目版本无缝跨项目和平台

android - TextView 的自定义 ActionMode 不适用于所有设备

CSS "sunken"/"inset"不使用图片的字母效果

linux - 在不保持组顺序的情况下改组大型文本文件