0

我有以下包含一个按钮的布局,我正在尝试减小按钮的大小,主要是高度,但按钮高度允许保持不变

<LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/buttonlayout2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:gravity="right"
            android:orientation="horizontal"
           android:background="#FFDBE2ED"
             android:paddingBottom="0dp"
              android:paddingTop="0dp" >

            <!--Button
                android:id="@+id/btnSave"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="2px"
                android:layout_marginLeft="10px"
                android:layout_marginRight="10px"
                android:layout_marginTop="2px"
                android:height="15dp"
                android:text="Save"
                android:textSize="15sp"
                android:width="70dp" >
            </Button -->

            <Button
                android:id="@+id/btnClear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="0px"
                android:layout_marginLeft="10px"
                android:layout_marginRight="3px"
                android:layout_marginTop="2px"
                android:height="0dp"
                android:text="Clear"
                android:textSize="15sp"
                android:width="70dp"
                  >
            </Button>
       </LinearLayout>

任何想法?

4

3 回答 3

2

您正在使用android:layout_height="wrap_content"这意味着它将始终与其中的内容一样高。尝试使用该值来改变高度。

于 2012-08-20T21:12:21.343 回答
1

刚试过你的代码,按钮看起来不错。你想让它看起来像什么?按钮与当前 android 主题定义的一样小(短)。您必须将按钮样式更改为自定义样式,以使按钮内部的间距不同以使其更短。

当您放置标准 android 按钮时,android 将使用其主题样式,包括用于按钮背景的 9-patch 图像。该图像具有文本的内部填充。如果您需要按钮的不同外观,则需要创建一个从 Button 继承的自定义 Button 控件并覆盖样式。

于 2012-08-20T21:25:42.243 回答
1

android:layout_width="wrap_content"
android:layout_height="wrap_content"

wrap_content您可以使用 DP(密度独立像素)指定视图的宽度或高度,而不是使用,尝试更改wrap_content50dp适合您需要的任何值。

于 2012-08-20T21:16:31.287 回答