开发者

dynamically increase the relative layout size in android

i have a relative layout on which i am displaying a page and some content. when i zoom my page...the layout size is not increasing. i want my layout to increase its size dynamically. how do i set it?? i tried doing it in java code.

contentLayout.getLayoutParams().height = x (some value which is equal to the page size)
contentLayout.requestLayout()

but this is nt working. i开发者_运维问答 have also set the layout params android:layout_width and android:layout_height to wrap-content in the xml file.

Kindly, help me out. thank you


You can do it this way. I also added setting of the margins:

RelativeLayout targetItem = (RelativeLayout) findViewById(R.id.RelativeLayout01);
RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(mWidth, mHeight);
adaptLayout.setMargins(marginLeft, marginTop, marginRight, marginBottom);   
targetItem.setLayoutParams(adaptLayout);                    

For mWidth and mHeight you also may set dip values to make it adapt to the different screen sizes. Easy way to do that is to define Dimension in your strings.xml and work with them, not with absolute values.

So, if you define relative_width as 120dip, and relative_height as 100 dip then in code you have

RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(getResources().getDimension(R.dimen.relative_width), getResources().getDimension(R.dimen.relative_height));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜