【发布时间】:2017-10-01 04:06:14
【问题描述】:
你好伟大的社区。我是 Android 新手,正在尝试构建一个计算器,这是我第一次遇到这个问题,不知道出了什么问题。我添加了buttons,它们在模拟器上看起来很好,除了image button。代码如下,希望能得到帮助。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp"
android:weightSum="4">
<Button
android:id="@+id/button16"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_weight="1"
android:background="#00000000"
android:text="7"
android:textColor="@android:color/background_dark"
android:textSize="30sp"/>
<Button
android:id="@+id/button5"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_weight="1"
android:background="#00000000"
android:text="8"
android:textColor="@android:color/background_dark"
android:textSize="30sp"/>
<Button
android:id="@+id/button4"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_weight="1"
android:background="#00000000"
android:text="9"
android:textColor="@android:color/background_dark"
android:textSize="30sp"/>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_weight="1"
android:background="#00000000"
android:textColor="@android:color/background_dark"
app:srcCompat="@drawable/divide"/>
</LinearLayout>
最后一个除法按钮不可见,我添加了四个这样的线性布局,分别是 1、2、3、减号、4、5、6、乘法按钮,所有这些乘法、除法、加号和减号buttons 都没有不幸的是,看不到。
我刚刚开始,希望知道我哪里错了,我需要解决什么问题。
更新
请参阅我附上的上图。在模拟器中这个可见的Views 是Buttons,如果我将它们更改为ImageButton,views 就像等号一样。我已经更改了我的 png's 文件,但我无法理解我做错了什么
谢谢
【问题讨论】:
-
这段代码在我身边工作可能是你的svg图片有问题
-
我猜你是对的,我将这些更改为普通按钮,效果很好,图像按钮在背景更改时也可以正常工作,寻找其他图像以查看是否修复,谢谢跨度>
-
你在用什么 svg 或 png 文件来保存图片@Pankaj
-
它们是 png。我刚刚自己创建了新的 png 并尝试再次添加图像按钮,但是当它显示在屏幕上时,它在模拟器或物理设备上仍然不可见。可能是什么原因?
-
在
app:srcCompat="@drawable/divide"/>的位置尝试android:src="@drawable/divide"/>
标签: android calculator