user3299520
user3299520

Reputation: 21

Programmatically resize framelayout

I have something like that:

  <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/photo1"
            android:orientation="vertical" >
     <FrameLayout
                android:id="@+id/photo2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

    </FrameLayout>
    <Fragment>

</Fragment>
    </FrameLayout>

And I want to resize that photo2 FrameLayout.

public void setScreenSize() {
    Display display = getWindowManager().getDefaultDisplay();
    FrameLayout layout = (FrameLayout) findViewById(R.id.photo2);
    int screen_height = display.getHeight();
    screen_height = (int) (0.60*screen_height);
    LayoutParams parms = (LayoutParams) layout.getLayoutParams();
    parms.height = screen_height;
    }

Unfortunately this doesn't work and I don't know why.

Upvotes: 2

Views: 7852

Answers (2)

Pir Fahim Shah
Pir Fahim Shah

Reputation: 10623

If you want to change the size of FrameLyaout programmatically then copy and paste this code, its working 100%.

FrameLayout frame1 = (FrameLayout) findViewById(R.id.framelayout1);
frame1.getLayoutParams().height =460;
frame1.getLayoutParams().width = 350;
frame1.requestLayout();

Upvotes: 2

Aswin Rajendiran
Aswin Rajendiran

Reputation: 3409

Are you setting the height back to the layout?

public void setScreenSize() {
    Display display = getWindowManager().getDefaultDisplay();
    FrameLayout layout = (FrameLayout) findViewById(R.id.photo2);
    int screen_height = display.getHeight();
    screen_height = (int) (0.60*screen_height);
    LayoutParams parms = (LayoutParams) layout.getLayoutParams();
    parms.height = screen_height;
    // Set it back.
    layout.setLayoutParams(parms);
}

Upvotes: 2

Related Questions