调整Android的一个ImageButton的大小 [英] Adjusting the size of an ImageButton in Android

查看:342
本文介绍了调整Android的一个ImageButton的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做到这一点?我试图填补图像和设置视图的宽度/高度,但也似乎工作。下面是一个例子:

Is there any way to do this? I have tried padding the image and setting the width/height of the view, but neither seems to work. Here is an example:

<ImageButton
    android:id="@+id/search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/search_small"
    android:paddingTop="4sp"
    android:paddingBottom="4sp"
    android:paddingLeft="6sp"
    android:paddingRight="6sp"
    android:layout_marginRight="10sp"
    android:layout_marginTop="6sp"
    android:layout_marginBottom="6sp"
    android:layout_alignParentRight="true"
/>

我想按钮被更广泛的比它高,但它是走出倒过来。

I want the button to be wider than it is tall, but it is coming out the other way round.

推荐答案

刚刚有了一个戏,试图理解你的问题。

Just had a play to try and understand your problem.

好像的ImageButton 是有几个pre-设定值的复合视图。如某种形式的保证金,你不能用XM​​L重写。如果你不能改变你的形象以适应所要的结果,那么你最好创建自己的复合视图是什么。

Seems ImageButton is a composite view which has a few pre-set values. Such as some sort of margin which you cannot override with the XML. If you cannot change your image to match what you want to happen then you are better to create your own composite view.

下面是我的一个复合视图的例子中,你可以让自己:

Here is my example of a composite view you can make yourself:

    <FrameLayout                                        android:layout_width="wrap_content" android:layout_height="wrap_content">           
        <Button     android:id="@+id/saveSearchButton"  android:layout_width="50dp"         android:layout_height="50dp" />
        <ImageView                                      android:layout_width="45dp"         android:layout_height="45dp" android:scaleType="fitXY" android:src="@drawable/ic_menu_save" android:layout_gravity="center"/>
    </FrameLayout>
    <FrameLayout                                        android:layout_width="wrap_content" android:layout_height="wrap_content">           
        <Button     android:id="@+id/clearSearchButton" android:layout_width="50dp"         android:layout_height="50dp" />
        <ImageView                                      android:layout_width="45dp"         android:layout_height="45dp" android:scaleType="fitXY" android:src="@drawable/ic_menu_close_clear_cancel" android:layout_gravity="center"/>
    </FrameLayout>      

和原来的按钮:

    <ImageButton android:id="@+id/imageButton1" android:src="@drawable/ic_menu_save"                android:layout_height="45dp" android:layout_width="45dp"/>
    <ImageButton android:id="@+id/imageButton2" android:src="@drawable/ic_menu_close_clear_cancel"  android:layout_height="45dp" android:layout_width="45dp"/>  

在这里,我们可以看到自定义图像/按钮复合其次是建立在的ImageButton 作为SDK的一部分:

Here we can see custom image/button composite followed by the build in ImageButton as part of the SDK:

这篇关于调整Android的一个ImageButton的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆