在LinearLayout中将一个按钮的空间销毁到另一个按钮

时间:2015-10-19 08:49:22

标签: android android-linearlayout

当我设计计算器的布局时遇到了一些麻烦。如图所示,我希望它看起来像pic1,但无论我如何更改代码,它仍然看起来像pic2。这是照片和我的代码!希望有人能帮我解决这个问题。

(PIC1)
enter image description here

(PIC2)
enter image description here

代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/question_text_view"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:padding="24dp" />

    <LinearLayout
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:orientation = "horizontal" 
        android:layout_weight="0">

        <Button
            android:id = "@+id/C_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"

            android:text = "C" />

        <Button
            android:id = "@+id/del_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "del" />

        <Button
            android:id="@+id/divide_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="/"/>

        <Button
            android:id="@+id/mul_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"      
            android:text="X"/>
    </LinearLayout>    

    <LinearLayout
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:orientation = "horizontal" 
        android:layout_weight="0">

        <Button
            android:id = "@+id/seven"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "7" />

        <Button
            android:id = "@+id/eight_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "8" />

        <Button
            android:id="@+id/nine_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="9"/>

        <Button
            android:id="@+id/minus_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"      
            android:text="-"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:orientation = "horizontal" 
        android:layout_weight="0">

        <Button
            android:id = "@+id/four"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "4" />

        <Button
            android:id = "@+id/five_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "5" />

        <Button
            android:id="@+id/six_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="6"/>

        <Button
            android:id="@+id/plus_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"      
            android:text="+"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:orientation = "horizontal" 
        android:layout_weight="0">

        <Button
            android:id = "@+id/one"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "1" />

        <Button
            android:id = "@+id/two_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text = "2" />

        <Button
            android:id="@+id/three_button"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="3"/>

        <Button
            android:id="@+id/equal_button"
            android:layout_rowSpan="2"
            android:layout_gravity="fill"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:text="="/>
    </LinearLayout>
</LinearLayout>

2 个答案:

答案 0 :(得分:1)

只需替换Button的背景,Android的默认按钮在背景图片中有透明像素

答案 1 :(得分:1)