i have a problem about ScrollView

i want add myView(extends View) to the ScrollView, myView i will draw
something, image or text,
but when i create myView and add it in the scrollView ,but get the
Height = 0  onSizeChanged(), i don't know why?

(1) myActivity
        final LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));


        LinearLayout.LayoutParams paramS = new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT,1);
        scroll = new ScrollView(this);
        ViewGroup.LayoutParams paramSvLp = new ScrollView.LayoutParams
(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        scroll.setLayoutParams(paramS);
        layout.addView(scroll);

        history = new HistoryTextView(this);
        history.setLayoutParams(paramSvLp);
        scroll.addView(history);

(2) HistoryTextView

public class HistoryTextView extends LinearLayout{
          private Activity activity;
          private EmotionTextView topText;

          public HistoryTextView(Context context){
            super(context);
            activity = (Activity) context;
            setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
            setOrientation(LinearLayout.VERTICAL);
            setGravity(Gravity.FILL);
                    addItem(str);
          }

          public void addItem(String str)
          {
                LayoutParams params1 = new LayoutParams
(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);
                EmotionTextView etv1 = new EmotionTextView(getContext(),
null);
                String show1=" 12345678 :) ";

                etv1.setLayoutParams(params1);
               // etv1.invalidate();
                addView(etv1);
                etv1.setShowText(show1);
          }
}


(3) EmotionTextView

public class EmotionTextView extends View{
        public String showText;
        public Paint paint;
        public EmotionTextView(Context context, AttributeSet attrs) {
                super(context, attrs);
                // TODO Auto-generated constructor stub


        //setFocusable(true);
        paint = new Paint();
        paint.setTextSize(20);
        paint.setColor(Color.BLUE);
        paint.setAntiAlias(true);
        }

        public void setShowText(String showText)
        {
                this.showText=showText;

        }


        protected void onSizeChanged(int w, int h, int oldw, int oldh)
        {
                width=w;  //w = 0???
                init();
        }



    @Override
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawColor(0xfff00fff);
}
--~--~---------~--~----~------------~-------~--~----~
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