0

I am dynamiclly creating a View which contains an image and a TextView this is then being added to a ViewFlipper. This is all working as it should the issue is I require the scrollbar to always be visible, however I simple cannot get it to work and am not sure what I am doing wrong.

Below is my dynamic code and the xml code which I am trying to replicate

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 code I am trying to replicate programatically

<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="" />
SingleWave Games
  • 2,618
  • 9
  • 36
  • 52

1 Answers1

1

How about trying to use a ScrollView as the top most parent. So, something like this:

// 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);

Or, if it's just the text you want to scroll, make the first LinearLayout a Scrollview:

// Creating my linear layouts & views
    lls = new ScrollView(this); // This wraps your textView
    llv = new LinearLayout(this);  
    lls.setOrientation(LinearLayout.VERTICAL);

NOTE: this is not tested. Just trying to give you an idea. You may have to specify more layout parameters for the ScrollView to get this to work.

You can also take a look at this post where they talk about setting:

textView.setMovementMethod(new ScrollingMovementMethod())
Community
  • 1
  • 1
SBerg413
  • 14,515
  • 6
  • 62
  • 88
  • This doesnit seem to work, its not allowing me to set a orientation to teh scrollview. Also, this will make both the image and textview scrollable, which is not what am after. Ideally I woudl like to avoid ScrollView, as you can see from the xml, I had this working perfectly. Thanks. – SingleWave Games Oct 17 '13 at 15:14
  • As I mention in my answer, you can wrap JUST the TextView in the ScrollView. This should in theory work fine and save you a lot of headache. Anyway, hope you figure it out. – SBerg413 Oct 17 '13 at 15:25
  • I am already using setMovementMethod, I will try to implement a scrollView around the TextView. – SingleWave Games Oct 17 '13 at 15:39
  • I had to amend your code slightly, essentially I added the imageview to linearlayout and textview to scrollview then added both those to another vertical orientated linearlayout, which i then added to the viewflipper. That got it working, thanks. – SingleWave Games Oct 17 '13 at 15:45