0

My ImageButton isn't rescaling like the code is telling it to. Infact it's not doing anything.

Code:

public void getScreenRes(){
    DisplayMetrics display = this.getResources().getDisplayMetrics();
    int width = display.widthPixels;
    int height = display.heightPixels;
    int buttonheight = display.heightPixels / 8;
    double buttonwidth = buttonheight * 2.66666667;
    int buttonwidthint = (int) Math.round(buttonwidth);
    ImageButton firsttimeFB = (ImageButton) findViewById(R.id.firsttime_fb);
    firsttimeFB.setMaxWidth(buttonwidthint);
    firsttimeFB.setMaxHeight(buttonheight);
}

XML

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/facebook"
    android:id="@+id/firsttime_fb"
    />
343N
  • 296
  • 2
  • 4
  • 19

2 Answers2

0

The problem is probably that in xml you're defining width and height as "wrap_content"

Look at this answer: Resize ImageButton?

Community
  • 1
  • 1
vipluv
  • 607
  • 5
  • 8
  • I changed it but it's still not doing anything it's staying as the XML is set. I want it to resize dynamically to the size I give it – 343N Jan 28 '15 at 09:54
0

Replace your last three lines of code to:

ImageButton firsttimeFB = (ImageButton) findViewById(R.id.firsttime_fb);
firsttimeFB.getLayoutParams().width=buttonwidthint;
firsttimeFB.getLayoutParams().height=buttonheight;

You should set width instead of max width and same for height.

Karn Shah
  • 501
  • 4
  • 14