Android 将按钮添加到onClick时是否会收缩?

Android 将按钮添加到onClick时是否会收缩?,android,button,background-image,android-button,Android,Button,Background Image,Android Button,我在线性布局中添加了3个按钮,并在我的活动中为它们分配了一个onClick侦听器,其中两个按钮仅收缩和包装运行代码时包含的文本 第三个会在单击后收缩: 我正在使用的按钮: 我在XML中使用的代码: <LinearLayout android:id="@+id/bottomButtons" android:layout_width="match_parent" android:layout_height="wra

我在线性布局中添加了3个按钮,并在我的活动中为它们分配了一个onClick侦听器,其中两个按钮仅收缩和包装运行代码时包含的文本

第三个会在单击后收缩:

我正在使用的按钮:

我在XML中使用的代码:

<LinearLayout
            android:id="@+id/bottomButtons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/LivingRoom"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ac_button_active"
                android:text="Living Room"
                android:textSize="20dp"
                android:textColor="#00CCCC"
                android:layout_marginTop="3dp"
                android:layout_marginLeft="3dp"
                android:layout_marginBottom="3dp"
                android:layout_marginRight="3dp"
                android:tag="pressed" />

            <Button
                android:id="@+id/NoAC"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ac_button_inactive"
                android:text="No AC"
                android:textSize="20dp"
                android:textColor="#00CCCC" 
                android:layout_marginTop="3dp"
                android:layout_marginLeft="3dp"
                android:layout_marginBottom="3dp"
                android:layout_marginRight="3dp"
                android:tag="transparent"/>

            <Button
                android:id="@+id/office"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ac_button_inactive"
                android:text="Office"
                android:textSize="20dp"
                android:textColor="#00CCCC" 
                android:layout_marginTop="3dp"
                android:layout_marginLeft="3dp"
                android:layout_marginBottom="3dp"
                android:layout_marginRight="3dp"
                android:tag="transparent"/>


当您使用9-patch图像作为背景时,它们将被缩小/调整以完全适合按钮大小。按钮大小取决于文本大小及其宽度

所以,若你们需要的话,可以用填充物来增加按钮的尺寸和边距

<Button
    .......
    android:paddingBottom="5dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="5dp" 
   ..........              />


是否在代码中修改视图?按钮的背景是否可彩色绘制?你能发布@drawable/ac_button_inactive和所有按钮的背景吗?你使用的是9-patch图像吗?尺寸变大了一点,但仍然存在相同的问题。问题可能是你使用的背景drawable…给了我相同的答案result@MRefaat尝试使用android:gravity=“center”作为按钮。