如何从PNG制作图像按钮?

问题描述

我正在尝试从 png 实现一个图像按钮。 但是,我既不能实现我的半透明背景(它保持方形网格),也不能将它放在正确的角落!任何帮助解决这两个问题的帮助将不胜感激。 代码

<ImageButton
        android:id="@+id/maps_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/maps_symbol"
        android:scaleX="0.12"
        android:scaleY="0.12"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:background="#50F8F5F5"
        android:layout_marginBottom="10sp"
        />

目前情况照片:

enter image description here

解决方法

 app:layout_constraintBottom_toBottomOf="parent"
 app:layout_constraintEnd_toEndOf="parent" 

根据您的限制,图像将位于中心(如果没有给定边距)

您可以将约束更改为与该图像相邻

app:layout_constraintStart_toEndOf="@+id/button1" 
app:layout_constraintBottom_toBottomOf="parent"

或有

app:layout_constraintStart_toStartOf="parent" 
app:layout_constraintBottom_toBottomOf="parent" and give required android:layout_margin 

我假设你通过缩小它来缩小它,它可能看起来更小但轮廓仍然是相同的大小,改变图像的宽度和高度

<ImageButton
        android:id="@+id/maps_button"
        android:layout_width="12dp" //desired dimensions
        android:layout_height="12dp" //desired dimensions
        android:src="@drawable/maps_symbol"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:background="#50F8F5F5"
        android:layout_marginBottom="" //desired dimensions
        android:layout_marginStart= "" 
        />

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...