Android:减小Button的大小 [英] Android : Decreasing size of the Button

查看:456
本文介绍了Android:减小Button的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在其中一种布局中使用Button.我希望Button的大小与文本/标签的大小一样小.

I am using Button in one of the layouts. I want Button size to be as small as the text/label size.

我正在使用以下代码.

<Button 
android:text="@string/cancle_button" 
android:id="@+id/button1" 
android:background="@drawable/back_button" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="12sp"
android:textColor="#ffffff"
android:textStyle="bold" />

但是我希望Button的高度与文本/标签的高度相同.每当我减小或增加文本高度时,Button高度都保持不变.我该如何解决这个问题?

But I want Button height to be same as text/label height. Whenever I decrease or increase the text height, Button height remains the same. How should I solve this problem?

推荐答案

您可以使用相对布局来实现此目的.检查此示例代码,

You can use a relative layout to achieve this. Check this sample code,

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="TextView" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/textView1"
        android:layout_alignTop="@id/textView1"
        android:layout_alignBottom="@id/textView1"
        android:text="Button" />

</RelativeLayout>

这篇关于Android:减小Button的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆