Hi,

I've created an app that handles all the layouts by drawing them
manually thru each viewgroup's onLayout function respectively. In one
of the custom layouts (ViewGroups) i want to have a ScrollView (at
position x,y that not takes up the whole screen) with another custom
view in it. The view inside the ScrollView will have an adjustable
height but fixed width. The problem is that when updating the content
in the adjustable view (so that its size will increase), you need to
relayout the ScrollView so that it lays the view with the correct
size. I've tried with requestLayout on both the view and the
ScrollView, but nothing seems to happen. Any ideas what can be wrong?

ScrollView:



public SplitpanelView(Context context){
                super(context);
                this.context = context;
                //list = new SplitList(context);
                //list.setLayoutParams(new
ScrollView.LayoutParams(ScrollView.LayoutParams.WRAP_CONTENT,
ScrollView.LayoutParams.WRAP_CONTENT));

                list = new SplitList(context);

        addView(list);
        this.setBackgroundColor(Color.YELLOW);
        }

        //
        // Add method that adds split to the array:
        //
        public void Add(long ms){
                list.Add(ms);
                requestLayout();
        }

        public void clear(){
                list.Clear();
        }

        @Override
        public void onMeasure(int width, int height){
                list.height = list.splits.size() * 42;
                Toast.makeText(context, new Integer(height).toString(),
Toast.LENGTH_SHORT).show();
                setMeasuredDimension(315, height);
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b)
{
                // This layout is static, which means that you have to draw the
children manually:
                        // Renders the background and text:
                for(int i = 0; i < this.getChildCount(); i++){
                        View child = getChildAt(i);
            if (child.getVisibility() != GONE) {
                int w = 0;
                int h = 0;
                measure(w, h);
                child.layout(0, 0, 315, list.getHeight());
                Toast.makeText(context, new
Integer(list.getWidth()).toString() + " " + new
Integer(list.getHeight()).toString(),
                        Toast.LENGTH_SHORT).show();
            }
                }
        }





View inside the ScrollView:




public SplitList(Context context){
                super(context);
                this.context = context;

                Add(1);
                Add(2);
                Add(3);

                text = new Paint();
                text.setTextSize(25f);
                text.setColor(Color.BLACK);
                text.setDither(true);
                text.setAntiAlias(true);
                text.setTypeface(Typeface.DEFAULT);
                this.setScrollContainer(true);
        }

        //
        // Add method that adds split to the array:
        //
        public void Add(long ms){
                splits.add(ms);
        }

        public void Clear(){
                splits.clear();
        }

        @Override
        public void onMeasure(int width, int height){
                height = splits.size() * 42;
                Toast.makeText(context, new Integer(height).toString(),
Toast.LENGTH_SHORT).show();
                setMeasuredDimension(315, height);
        }

         @Override
     protected void onLayout(boolean changed, int left, int top, int
right, int bottom) {
                     int newleft = 0;
                     int newRight = 0;
                     int newTop = 0;
                     int newBottom = 0;
                     this.measure(newRight, newBottom);
                     super.onLayout(changed, newleft, newTop, 315,
height);
                     requestLayout();
     }

        //
        // Override the onDraw function to draw the view:
        //
        @Override
        public void onDraw(Canvas c){
                Paint text2 = new Paint();
                text2.setColor(Color.RED);
                c.drawRect(0, 0, this.getWidth(), this.getHeight(), text2);

                // Draw left column:
                for(int i = 0; i < splits.size(); i++){
                        String time = Misc.GetStringFromMS(splits.get(i));
                        float text_X = (140 - text.measureText(time));
                        c.drawText(time, text_X, 32 + (42 * i), text);

                        time = Misc.GetStringFromMS(splits.get(i));
                        text_X = (282 - text.measureText(time));
                        c.drawText(time, text_X, 32 + (42 * i), text);
                }
        }

-- 
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