2
我想在運行時在我的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);
工作。但是當我同時使用水平和垂直時,它不能正常工作......
到目前爲止,我可以在運行時添加veritcal滾動視圖,但我想要水平和垂直 –
您可以像ScrollView一樣實現'HorizontalScrollView'。你在這方面掙扎着什麼?你是否希望垂直*和*水平滾動相同的'視圖'? – Eric
是的..我應該能夠垂直和水平滾動也。 –