![](/img/trans.png)
[英]Programmatically scroll a ScrollView to focus on a Button or a view - Android
[英]Android: Adding a Button to a ScrollView programmatically
我有一个ScrollView
其中包含许多buttons
和textviews
。
我希望在滚动视图的中间insert a new button
(索引3),但收到错误消息“ ScrollView只能容纳一个直接子对象 ”
这不可能吗?
Button b = new Button(this);
scrView.AddView(b,3);
????
将子视图放在诸如LinearLayout
或RelativeLayout
之类的布局中,然后将布局置于ScrollView
。 将视图添加到布局中,而不是ScrollView
。
不,您不能在scollview中添加多个视图,因为您现在知道“ ScrollView只能容纳一个直接子级”
您将最终在scollview中使用线性布局,在此之前您会添加其他按钮,因此在其中添加新按钮……
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.