2013-10-17 61 views
0

我是dynamiclly創建一個包含圖像和TextView然後被添加到ViewFlipper的視圖。這是所有工作,因爲它應該的問題是我需要滾動條總是可見的,但我簡單的不能讓它工作,我不知道我做錯了什麼。android - TextView獲取滾動條總是以編程方式顯示

下面是我的動態代碼和我試圖複製我試圖複製編程

<TextView 
    android:id="@+id/txtStoryText" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imgStoryLine" 
    android:layout_above="@+id/footer" 
    android:layout_margin="20dp" 
    android:scrollbars="vertical" 
    android:scrollbarSize="10dp" 
    android:fadeScrollbars="false" 
    android:textColor="@color/orange" 
    android:text="" /> 

回答

1

如何試圖用一個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()) 
+0

這doesnit似乎工作,它不是讓我一個方向設置爲滾動型德。此外,這將使圖像和文本視圖滾動,這不是什麼後。理想情況下,我想避免使用ScrollView,就像你從xml中看到的那樣,我的工作很完美。謝謝。 –

+0

正如我在我的回答中提到的,你可以在ScrollView中包裝JUST TextView。這應該在理論上工作正常,併爲您節省很多頭痛。無論如何,希望你弄明白。 – SBerg413

+0

已更新的答案。你可以嘗試setMovementMethod()。 – SBerg413

相關問題