如何试图用一个ScrollView作为
for(int i = 0; i < 5; i++)
{
// Creating my linear layouts & views
lls = new LinearLayout(this);
llv = new LinearLayout(this);
lls.setOrientation(LinearLayout.VERTICAL);
// Adding image view
imgStory = new ImageView(this);
imgStory.setImageResource(GetImage(i));
imgStory.setLayoutParams(new LayoutParams(width, width));
lls.addView(imgStory);
// adding textview, which is scrollable
txtStory = new TextView(this);
txtStory.setText(unescape(story.get(i)));
txtStory.setTextColor(getResources().getColor(R.color.orange));
txtStory.setPadding((int)padding, (int)padding, (int)padding, (int)padding);
txtStory.setMovementMethod(new ScrollingMovementMethod());
//txtStory.setVerticalScrollBarEnabled(true);
//txtStory.setVerticalFadingEdgeEnabled(false);
lls.addView(txtStory);
// Adding views to my view flipper
llv.addView(lls);
viewFlipper.addView(llv, i);
}
XML代码的XML代码最顶级的家长。所以,这样的事情:
// Creating my linear layouts & views
lls = new LinearLayout(this);
llv = new ScrollView(this); // This looks like the view you're adding to the viewFlipper
lls.setOrientation(LinearLayout.VERTICAL);
或者,如果它只是要滚动文本,使第一的LinearLayout滚动型:
// Creating my linear layouts & views
lls = new ScrollView(this); // This wraps your textView
llv = new LinearLayout(this);
lls.setOrientation(LinearLayout.VERTICAL);
注:这不是测试。试图给你一个想法。您可能需要为ScrollView指定更多的布局参数才能使其发挥作用。
您还可以看看this post这里只讲设置:
textView.setMovementMethod(new ScrollingMovementMethod())
这doesnit似乎工作,它不是让我一个方向设置为滚动型德。此外,这将使图像和文本视图滚动,这不是什么后。理想情况下,我想避免使用ScrollView,就像你从xml中看到的那样,我的工作很完美。谢谢。 –
正如我在我的回答中提到的,你可以在ScrollView中包装JUST TextView。这应该在理论上工作正常,并为您节省很多头痛。无论如何,希望你弄明白。 – SBerg413
已更新的答案。你可以尝试setMovementMethod()。 – SBerg413