【发布时间】:2017-03-25 17:03:40
【问题描述】:
您好,我正在使用 Xamarin (C#),并且正在尝试开发 Android 应用程序, 我需要让我的内容可滚动,我知道我可以通过将 XML 文件更改为类似的东西来做到这一点
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Content here -->
</LinearLayout>
</ScrollView>
但我需要使用 C#(和 Xamarin)动态地执行此操作。这段代码生成了几个Button,放到linearLayout中,但是我需要把linearLayout放到scrollView中才能向下滚动看到其他按钮。
var linearLayout = new LinearLayout(this);
var scrollView = new ScrollView(this);
int count = 30;
linearLayout.Orientation = Orientation.Vertical;
....
for (int a = 1; a < count; a++)
{
var button = new Button(this);
linearLayout.AddView(Button);
}
SetContentView(linearLayout);
感谢您的回复或提示如何提前以其他方式进行操作。
【问题讨论】:
标签: c# android xml xamarin scrollable