我有一个相对布局,我正在显示一个页面和一些内容.当我缩放我的页面时......布局大小没有增加.我希望我的布局动态增加其大小.我该怎么设置?我尝试用java代码做.
contentLayout.getLayoutParams().height = x (some value which is equal to the page size)
contentLayout.requestLayout()
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我还设置布局PARAMS android:layout_width
并android:layout_height
以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);
Run Code Online (Sandbox Code Playgroud)
对于mWidth和mHeight,您还可以设置dip
值以使其适应不同的屏幕尺寸.简单的方法是在你的中定义Dimension strings.xml
并使用它们,而不是使用绝对值.
所以,如果你定义relative_width
为120dip,relative_height
然后在你的代码中定义为100 dip
RelativeLayout.LayoutParams adaptLayout = new RelativeLayout.LayoutParams(getResources().getDimension(R.dimen.relative_width), getResources().getDimension(R.dimen.relative_height));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6999 次 |
最近记录: |