如何从code机器人创造真正的小按钮? [英] How to create really small buttons in android from code?

查看:126
本文介绍了如何从code机器人创造真正的小按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的默认Button类提供了一个真正的大按钮。

Android default Button class provides a really big button.

有很多浪费的空间周围。现在,我要创建真正的小按钮,这仅仅比文本/标题稍微大一点。如何从code做到这一点? 到目前为止,我发现下面的方法,但它仍然提供过大的按钮和浪费太多的空间:

There is a lot of wasted space around. Now I want to create really small buttons, that are only slightly bigger than the text/caption. How to do this from code? So far I found the following method, but it is still providing too big buttons and wasting too much space:

一个。创建在res /布局XML(smallbutton.xml):

A. Create an XML (smallbutton.xml) in the res/layout:

<?xml version="1.0" encoding="utf-8"?>

    style="?android:attr/buttonStyleSmall"
    android:text="color"
    android:padding="0dp"
    android:layout_margin="0dp"

    android:textSize="8dp"
    android:maxHeight="2dp"
    android:maxWidth="2dp"

/>

乙。从你的code夸大这一点,并添加到视图:

B. From your code inflate this and add to the view:

Button pickBackColor = (Button) this.getLayoutInflater().inflate(R.layout.smalbutton,null);

...

LinearLayout linLayout = new LinearLayout(this);

linLayout.addView(pickBackColor);

现在的问题是,按钮还是太大,它使用太多空间周围(左侧,右侧,上方下)的文字。

Now the problem is that the button is still too big, it uses too much space around (on the left, right, above, under) of the text.

任何提示如何减少按钮的尺寸进一步?

Any hint how to decrease the size of the button further?

推荐答案

按钮有一个最小的高度和宽度(通常48dp分别64dp默认情况下)。所以添加

Buttons have a minimal height and width (typically of 48dp respectively 64dp by default). So add

android:minHeight="0dp"
android:minWidth="0dp"

要得到真正的小按钮:

这篇关于如何从code机器人创造真正的小按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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