有背景图象文本定位的按钮

时间:2017-04-28 13:31:32

标签: android xml button

我想将文字放在我的按钮中,如下所示:

enter image description here

此时文本位于按钮的左下角:

enter image description here

我有四排这种类型的按钮,每排有两个按钮。这是我的一行按钮的代码:

<Window.Resources>
    <local:ListViewEvenColumnWidthConverter x:Key="EvenColumnWidthConverter" ColumnCount="4" />
</Window.Resources>

...

 <ListView x:Name="listView" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
     <ListView.View>
         <GridView>
             <GridViewColumn Header="Date" Width="{Binding ElementName=listView, Path=ActualWidth, Converter={StaticResource EvenColumnWidthConverter}}" />
             <GridViewColumn Header="Supplier" Width="{Binding ElementName=listView, Path=ActualWidth, Converter={StaticResource EvenColumnWidthConverter}}" />
             <GridViewColumn Header="Product" Width="{Binding ElementName=listView, Path=ActualWidth, Converter={StaticResource EvenColumnWidthConverter}}" />
             <GridViewColumn Header="Quantity Sold" Width="{Binding ElementName=listView, Path=ActualWidth, Converter={StaticResource EvenColumnWidthConverter}}" />
             ...
        </GridView>
    </ListView.View>
        Test Text
</ListView>

如何在不移动背景图像的情况下在文本的左侧和下方添加一些填充?边距似乎在按钮周围添加了空白区域,填充在背景图像和按钮边缘之间创建了空间。

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

您可以使用此

   <TextView
    android:id="@+id/main_fashion_button"
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:background="@mipmap/ic_launcher"
    android:text="Fashion"
    android:textColor="#FFFFFF"
    android:gravity="bottom"
    android:padding="10dp">

答案 1 :(得分:0)

检查出来

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:src="@drawable/image" />

    <TextView
        android:id="@+id/imageViewText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|left"
        android:layout_alignBottom="@+id/imageButton"
        android:text="FASHION"
        android:padding="16dp"
        android:textColor="#fff" />

</RelativeLayout>