小编Sah*_*arg的帖子

在android中运行时更改ImageButton的宽度和高度

我已经使用此代码制作了一个ImageButton&之后我想在运行时更改它的大小.这两个代码都写在下面,

 <ImageButton
    android:id="@+id/btn_new"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/untitled3"
    />
Run Code Online (Sandbox Code Playgroud)
 public void scaler1() {
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();
    btn_new.setMinimumWidth(width/4);
    btn_new.setMinimumHeight(height/6);
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用请给出任何解决方案.

这是我正在使用的实际代码

  public void scaler1() {
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();

    edit_screen.setWidth(width);
    edit_screen.setHeight(height / 6);

    lpsame = (LayoutParams) btn_0.getLayoutParams();
    lpsame.width=width/4;
    lpsame.height=height/6;

    btn_0.setLayoutParams(lpsame);



    LayoutParams lpedit = (LayoutParams) edit_screen.getLayoutParams();
    lpedit.width=width;
    lpedit.height=height/6;

    LayoutParams lpequal = (LayoutParams) btn_0.getLayoutParams();
    lpequal.width=width/2;
    lpequal.height=height/6;

    edit_screen.setLayoutParams(lpedit);


    btn_2.setLayoutParams(lpsame);
    btn_3.setLayoutParams(lpsame);
    btn_4.setLayoutParams(lpsame);
    btn_5.setLayoutParams(lpsame);
    btn_6.setLayoutParams(lpsame);
    btn_7.setLayoutParams(lpsame);
    btn_8.setLayoutParams(lpsame);
    btn_9.setLayoutParams(lpsame);
    btn_add.setLayoutParams(lpsame);
    btn_subtrac.setLayoutParams(lpsame); …
Run Code Online (Sandbox Code Playgroud)

height android runtime width imagebutton

0
推荐指数
1
解决办法
1929
查看次数

标签 统计

android ×1

height ×1

imagebutton ×1

runtime ×1

width ×1