我想在运行时在我的 Android 应用程序中添加水平和垂直滚动视图。
ScrollView sv = new ScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setBackgroundResource(R.drawable.opsbuds);
ll.setLayoutParams (new LayoutParams
(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
ll.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(40, 20, 0, 0);
sv.addView(ll);
现在我的代码是这样的,但它不能正常工作
ScrollView sv = new ScrollView(this);
HorizontalScrollView horizontal = new HorizontalScrollView(this);
LinearLayout ll = new LinearLayout(this);
ll.setBackgroundResource(R.drawable.opsbuds);
ll.setLayoutParams (new LayoutParams
(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
ll.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(40, 20, 0, 0);
horizontal.addView(ll);
通过使用上面的代码,我可以添加垂直滚动视图。但是当我同时使用水平和垂直时,它并没有正常...