我有一个相对布局,在其中显示页面和一些内容。当我缩放页面时...布局尺寸没有增加。我希望我的布局能够动态增加其大小。我该如何设置?
我尝试用java代码来做。
contentLayout.getLayoutParams().height = x (some value which is equal to the page size)
contentLayout.requestLayout()
但这不起作用。我还设置了布局参数android:layout_width
and android:layout_height
to wrap-content
在 xml 文件中。
请帮帮我。谢谢
你可以这样做。我还添加了边距设置:
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 你也可以设置dip
值以使其适应不同的屏幕尺寸。简单的方法是在您的strings.xml
并与他们一起工作,而不是绝对价值观。
所以,如果你定义relative_width
为 120dip,以及relative_height
作为 100 浸然后在代码中你有
RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(getResources().getDimension(R.dimen.relative_width), getResources().getDimension(R.dimen.relative_height));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)