动态增加的android相对布局尺寸 [英] dynamically increase the relative layout size in android
问题描述
我有一个相对布局上我是显示一个页面,一些内容。当我放大我的网页...布局规模不增加。我想我的布局,以动态地增加其大小。我该如何设置呢?? 我试图做它在Java code。
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()
但这是NT工作。我还设置布局PARAMS 的android:layout_width
和安卓layout_height
到包装内容
在XML文件中。
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.
请,帮助我。谢谢
推荐答案
您可以这样来做。我还添加设置页边距的:
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);
有关mWidth和mHeight您还可以设置浸
值,使之适应不同的屏幕尺寸。简单的方法就是在你的的strings.xml
,并与他们合作定义尺寸,不具有绝对的价值。
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.
所以,如果你定义 relative_width
为120dip,和 relative_height
100畅游则在code您有
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));
这篇关于动态增加的android相对布局尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!