2013-02-25 154 views
1

我正在尝试更改我的应用中几个按钮的高度。更改按钮的高度

my app screenshot

我已经尝试设置@android:color/transparent作为android:background,我也尝试了layout_height设定值一样16dp

我怎么能给我的按钮更小的高度?

这里是风格的XML:

<style name="Theme.PMBAppTheme.TextButton"> 
    <item name="android:textStyle">bold</item> 
    <item name="android:textSize">14sp</item> 
    <item name="android:textColor">@drawable/text_button_text</item> 
    <item name="android:background">#ff3300</item> 
    <item name="android:padding">0dp</item> 
    <item name="android:height">20sp</item> 
</style> 

而且布局:

<Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/register_btn_privacy" 
     android:text="@string/privacy_policy" 
     style="@style/Theme.PMBAppTheme.TextButton" 
     /> 

text_button_text

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_focused="true" android:state_pressed="true" android:color="@color/muted_pink_over" /> 
    <item android:state_focused="false" android:state_pressed="true" android:color="@color/muted_pink_over" /> 
    <item android:color="@color/muted_pink" /> 
</selector> 
+0

你可以发布你的XML – Kirk 2013-02-25 18:04:16

+0

@Kirk - 抱歉,完全忘了这么做。它现在在那里。 – boz 2013-02-26 09:14:19

回答

4

设置按钮的高度,为wrap_content:

android:layout_height="wrap_content" 

应该将按钮的高度设置为最小以显示其文本。

+0

我已经将它设置为'wrap_content',并产生了上述结果:( – boz 2013-02-26 09:13:45

1

Vapor API(我刚刚发布的一个针对Android的jQuery样式框架)中,有一种方法可以使用,名为.size(int,int)。这根据您所在的容器类型设置您的View的尺寸。因此,像:

$.Button(R.id.register_btn_privacy).size(int width, int height); 

什么是酷的,你也可以调用链调整View的其他属性。例如:

$.Button(R.id.register_btn_privacy) 
.size(50,100) // set size 
.text("Privacy Policy") // set the text 
.bgColor(Color.RED) // set the background color 
.color(Color.WHITE); // set the text color 

检查出来,如果你有兴趣在Vapor API website,它的基本设计,使Android开发人员轻松了许多,并像使用jQuery。

+0

这看起来很有趣,但我真的刚刚开始与Android开发。这将是很好的学习如何做的事情没有任何额外的框架/图书馆 – boz 2013-02-26 09:37:14

+0

这是公平的!只是抛出它,因为当我第一次来到Android时,我发现它有点混乱,祝你好运 – ComethTheNerd 2013-02-26 09:44:33

1

删除这个来自你的风采

<item name="android:height">20sp</item> 

所以,如果你TextView结束了

<style name="Theme.PMBAppTheme.TextButton"> 
    <item name="android:textStyle">bold</item> 
    <item name="android:textSize">14sp</item> 
    <item name="android:textColor">@drawable/text_button_text</item> 
    <item name="android:background">#ff3300</item> 
    <item name="android:padding">0dp</item> 
</style> 

Button继承并根据TextViewandroid:height,这大概正好设置高度,使其忽略您的layout_height

+0

谢谢,但这是不行的,我想我会去必须使用'TextView'并使其可点击而不是'Button' – boz 2013-02-26 17:21:20

+0

你能发布'@ drawable/text_button_text'的定义吗?也许在那里有一些意想不到的东西。 – Kirk 2013-02-26 18:08:15

+0

我已经更新了我的问题,它只是几种颜色。 – boz 2013-02-27 09:09:06