I required runtime dimensions of Relative/Linear Layout.
activity_home.xml:
<RelativeLayout
android:id="@+id/rlParent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
HomeActivity.java:
private int width, height;
RelativeLayout rlParent = (RelativeLayout) findViewById(R.id.rlParent);
w = rlParent.getWidth();
h = rlParent.getHeight();
Log.i("Width-Height", width+"-"+height);
Please share your thoughts.
private int width, height; RelativeLayout rlParent = (RelativeLayout) findViewById(R. id. rlParent); w = rlParent. getWidth(); h = rlParent.
The width and height can be obtained by calling getWidth() and getHeight().
RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets. TableLayout : is a view that groups its child views into rows and columns. FrameLayout : is a placeholder on screen that is used to display a single ...
First get layout params using view. getLayoutParams(). Second then set the height and width value then last set the layout params of view. Save this answer.
Try this
@Override
public void onWindowFocusChanged(boolean hasFocus) {
// TODO Auto-generated method stub
super.onWindowFocusChanged(hasFocus);
updateSizeInfo();
}
private void updateSizeInfo() {
RelativeLayout rlayout = (RelativeLayout) findViewById(R.id.rlayout);
w = rlayout.getWidth();
h = rlayout.getHeight();
Log.v("W-H", w+"-"+h);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With