Android的 - 编程指定新的滚动型的高度和宽度 [英] Android - Programmatically specify height and width of new ScrollView

查看:130
本文介绍了Android的 - 编程指定新的滚动型的高度和宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的Andr​​oid和我通过一个教程编程创建一个布局,而不是通过XML,我八九不离十卡可有人提醒,请做工作。

I'm new to Android and I'm working through a tutorial on programmatically creating a layout instead of doing it through the xml, I'm sorta stuck can someone advise please.

所以我有一个滚动型则增加了一个的LinearLayout进去,我想无论是一个特定的大小 - 480 * 800(code以下)。我能够设置大小的LinearLayout中,但我不能让滚动型也可以是大小,但我无法找到如何做到这一点。

So I have a ScrollView then have added a LinearLayout into it, I want both to be a specific size - 480 x 800 (code below). I was able to set the size in the LinearLayout but I cannot get the ScrollView to also be that size but I can't find how to do it.

这是可能的,因此我可以只指定了滚动型尺寸,并获得后续视图继承了。

Is this possible, and can I therefore just specify the ScrollView dimensions and get the subsequent views to inherit that.

ScrollView home_scroll = new ScrollView(this);
LinearLayout home_linear = new LinearLayout(this);
home_linear.setOrientation(LinearLayout.VERTICAL);

home_scroll.addView(home_linear, new LinearLayout.LayoutParams(480, 800));

任何帮助将是很大的AP preciated,谢谢。

Any help would be greatly appreciated, thanks.

推荐答案

尝试设置它像这样的:

home_scroll.setLayoutParams(new ViewGroup.LayoutParams(480, 800));
home_scroll.addView(home_linear, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

在LinearLayout中现在应该填补了滚动视图。

The linearlayout should now fill the scrollview.

这篇关于Android的 - 编程指定新的滚动型的高度和宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆