如何改变的ImageButton的大小机器人编程 [英] How to change size of imagebutton in android programatically

查看:144
本文介绍了如何改变的ImageButton的大小机器人编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要编程方式创建几个按钮imagebuttons,我不知道如何改变它们的大小。更换左,右不起作用。


解决方案

 在这里,如果你想改变按钮的大小,你已经在这里更改XML code将其去。     <的FrameLayout的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>
            <按钮机器人:ID =@ + ID / saveSearchButton的android:layout_width =50dp机器人:layout_height =50dp/>
            < ImageView的机器人:layout_width =45dp机器人:layout_height =45dp机器人:scaleType =fitXY机器人:SRC =@绘制/ ic_menu_save机器人:layout_gravity =中心/>
        < /&的FrameLayout GT;
        <的FrameLayout的android:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT>
            <按钮机器人:ID =@ + ID / clearSearchButton的android:layout_width =50dp机器人:layout_height =50dp/>
            < ImageView的机器人:layout_width =45dp机器人:layout_height =45dp机器人:scaleType =fitXY机器人:SRC =@绘制/ ic_menu_close_clear_cancel机器人:layout_gravity =中心/>


  // ImageView的设置
ImageView的ImageView的=新ImageView的(本);//设置高度和ImageView的宽度
的LayoutParams PARAMS =新的LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);//设置围绕imageimageview利润率
`params.setMargins(10,10,10,10); //`左,上,右,下//添加属性的ImageView的
imageView.setLayoutParams(PARAMS);

I have to create few buttons imagebuttons programatically and i don't know how to change size of them. Changing left and right does not work.

解决方案

Here if you want to change the size of the button, you have to change the xml code here it goes.

     <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"/>


//ImageView Setup
ImageView imageView = new ImageView(this);

//setting height and width of imageview
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

//setting margins around imageimageview
`params.setMargins(10, 10, 10, 10);` //left, top, right, bottom

//adding attributes to the imageview
imageView.setLayoutParams(params);

这篇关于如何改变的ImageButton的大小机器人编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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