如何試圖用一個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