Hello guys,

I want to use scrollview in my app. I tried to add a text view into
the scrollview, but I can't see anything rendered, except the
background color of the scroll view.

here is how I did it:
public class MyView extends ViewGroup
{
        ScrollView myScrollview;
        Textview tv;

        public MyView(Context context) {
                myScrollView = new ScrollView(context);
                myScrollView.setBackgroundColor(0xfff00fff);

                textview=new TextView(context);

                textview.setLayoutParams(new
LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
                textview.setLayoutParams(params)
                textview.setText("sadfasdfasdfasdfasdfasdfasdfsadfsadf");

                textview.layout(0, 0, 1000, 2000);
                textview.setHeight(5000);
                textview.setWidth(3200);
                myScrollView .addView(tv);
                addView(myScrollview);
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b)
{
                // TODO Auto-generated method stub

                int width = r-l;
                int height =b-t;

                myScrollView .layout(0, 0, width, height-100);
        }
}


I found almost all the scrollview tutorial are using xml to define the
view. But I want to do it in a programmatic way. But anyway, I also
tried xml.

I copied Romain Guy's xml from here for testing :http://www.curious-
creature.org/2010/08/15/scrollviews-handy-trick/

The xml scrollview by itself is correct, if I create this scrollview
and add it to the activity, using

scrollview= (ScrollView)
getLayoutInflater().inflate(R.layout.scrollviewid,null);
setContentView(scrollview);

or setContentView(R.layout.scrollviewid);

it worked. However, if I want to make the scrollview a child view of
some other view, again I could only see the background of the
scrollview. nothing inside is rendered:

public class MyView extends ViewGroup
{
       ScrollView myScrollview;

        public MyView(Activity activity,Context context)
        {
                super(context);

                myScrollview= (ScrollView)
activity.getLayoutInflater().inflate(R.layout.restaurantcategoryselectorviewlayout,null);
                myScrollview.setBackgroundColor(0xfff00fff);

                addView(myScrollview);
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b)
{
                // TODO Auto-generated method stub

                int width = r-l;
                int height =b-t;

                myScrollview.layout(0, 0, width, height-100);
        }
}



What's wrong with my code? Is there any example of creating scrollview
with program not xml?

Also, are those java source code of android also at kernel.org? since
the git service is down, where can I download android source code?

Thanks you!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to