1

My application containing different layouts.one of them is a linear layout.it's content is dynamically adding.i want to make this layout horizontally scrollable while adding its content.for that i wrote the code given below..

 <LinearLayout android:id="@+id/scoreballparent_layout"
  android:layout_height="wrap_content"
 android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_above="@+id/score_layout">
  <HorizontalScrollView android:layout_height="wrap_content" 
  android:id="@+id/scrollView1" 
  android:layout_width="fill_parent" 
  >
      <LinearLayout android:layout_width="fill_parent" 
      android:id="@+id/scoreball_layout" 
      android:layout_height="wrap_content"
      >

      </LinearLayout>
   </HorizontalScrollView>
 </LinearLayout>

it is working..but i want to scroll it automatically while adding contents...can anybody help me plz...

more source code:

    private void scoreball_display(String score)
    {
        addscoreball = new Button(getApplicationContext());
        addscoreball.setId(134);
        if(score=="WD" || score=="NB")
        {
            addscoreball.setTextAppearance(this,R.style.plainText);
        }
        else{
            addscoreball.setTextAppearance(this,R.style.BoldText);
        }

        addscoreball.setText(score);
        addscoreball.setSingleLine(true);
        addscoreball.setBackgroundDrawable(getResources().getDrawable      (R.drawable.white_ball));
        addscoreball.setGravity(Gravity.CENTER_HORIZONTAL);
        addscoreball.setGravity(Gravity.CENTER_VERTICAL);
        LinearLayout.LayoutParams addscoreball_Params = 
            new LinearLayout.LayoutParams(35,35);  
        scoreballlayout.addView(addscoreball,addscoreball_Params);

        }

in this method it is adding more contents to my layout...

3 Answers 3

3

Put <ScrollView> as parent layout...

Sign up to request clarification or add additional context in comments.

1 Comment

u mean parent layout of horizontal scrollview?
1

You have to update your UI when new element is added

first initialize HorizonatlScrollView using the following code

HorizontalScrollView s = (HorizontalScrollView) findViewById(R.id.HorizontalScrollView01);

when a new element is added use the following line there to scroll your HorizontalScrollView

runOnUiThread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
                s.fullScroll(HorizontalScrollView.FOCUS_RIGHT);

            }
        });

Thanks Deepak

1 Comment

in scoreball_display method after you add view you have not called runOnUiThread(new Runnable() { .....
0

There is a scrollTo method, see http://developer.android.com/reference/android/widget/HorizontalScrollView.html#scrollTo(int, int)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.