Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button with image and text and text bellow the image, how?

First time with cross-platform apps with xamarin, i'm working with xamarin forms in visual studio 2017 community.

I have a button with an image and text but the text needs to be below the image. currently the text is displaying to the left of the image, how can i do this?

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,
                }
            }
            }


        };
    }
}
}
like image 249
Medina Nualart Martin Avatar asked Jul 08 '17 16:07

Medina Nualart Martin


People also ask

How do I put text at the bottom of an image in HTML?

This can be done by enclosing the image and text in an HTML “div”. Then make the position of div “relative” and that of text “absolute”. The absolute elements are positioned relative to their parent (div). The top, right, bottom, and left properties of these elements specify their location from the parent.

How do I put text on an image button?

You cannot set text to ImageButton because it has no method as setText() or android:text property. ImageButtons can't have text (or, at least, android:text isn't listed in its attributes). It looks like you need to use Button (and look at drawableTop or setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)) .

How do I put text and images side by side in HTML?

<IMG SRC=”building. jpg” ALIGN=”right” />This text flows on the left. You can even flow text around an image placed on the left side of the page and then make the text wrap around a different image placed on the right side. In this instance, the break element <B /> and its one attribute, Clear, come into use.


1 Answers

You need to use ContentLayout on your button.

Here is the code I use in XAML:

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

Top = Position of the Image

0 = spacing between image & text

You should find easily how to use the ContentLayout in C#

like image 167
hugo Avatar answered Sep 25 '22 02:09

hugo