【发布时间】:2017-12-31 11:08:40
【问题描述】:
这是我的代码
mainView = new MainView(this, imageId, text, 3);
mainView.setOnTouchListener(this);
LinearLayout.LayoutParams mainParams = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
LinearLayout mainLinear = new LinearLayout(this);
ScrollView.LayoutParams scrollParams = new
ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
ScrollView scrollView = new ScrollView(this);
LinearLayout.LayoutParams myViewParams = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mainLinear.addView(mainView, myViewParams);
scrollView.addView(mainLinear, mainParams);
addContentView(scrollView, scrollParams);
当然,它仅适用于LinearLayout。请告诉我如何将其放入ScrollView。
【问题讨论】:
-
您可以尝试将
LinearLayout的大小设置为WRAP_CONTENT而不是MATCH_PARENT。还有(不相关的)你为什么用 Java 而不是 XML 做这个? -
你遇到什么崩溃了吗?
-
Henry
-
lib4
-
可以发布 MainView 类吗?或有关它的详细信息。
标签: android scrollview