[英]How do I remove the white padding around my imagebutton?
My app looks like this: 我的应用程序如下所示:
I want my two image buttons to completely fill the space of my linearlayout, the way the Checkbox does - none of that white padding around them. 我希望我的两个图像按钮完全像Checkbox一样填充线性布局的空间-它们周围没有白色填充。 I tried so many things suggested on stackoverflow = making the background "@null" and so on, but none of them worked.
我尝试了很多关于stackoverflow的建议=使背景“ @null”,依此类推,但是没有一个起作用。
I suppose I could try an ImageView, but I want to have that 'click' effect. 我想我可以尝试ImageView,但是我想拥有那种“点击”效果。
Any ideas? 有任何想法吗? Here's my code :
这是我的代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
tools:context=".MainActivity">
<ListView
android:id="@+id/ListView_2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1">
</ListView>
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/editText"
android:gravity="center"
android:inputType="phone"
android:background="#d9d9d9">
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal" >
<CheckBox
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:background="#ffa500"
android:text="New CheckBox"
android:id="@+id/checkBox"
android:layout_weight="2"
>
</CheckBox>
<ImageButton
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="@+id/imageButton"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<ImageButton
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="@+id/imageButton2"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
Please set your ImageView backgrouund to transparent and set your color or drawable in src. 请将ImageView背景设置为透明,并在src中设置颜色或可绘制。 Something like this:
像这样:
<ImageButton
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:id="@+id/imageButton"
android:background="@android:color/transparent"
android:src="?colorPrimary"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
You could use setPadding()
to remove the space between the image and the border. 您可以使用
setPadding()
删除图像和边框之间的空间。 This actually worked for me when making something similar in school. 在学校做类似的事情时,这实际上对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.