As the title says, i am trying to use a custom view i have created and
initializing the size of it using the above xml code snippet located
inside my layout folder.:

<com.Resources.Gui.ScrollingText  android:id="@+id/rss"
                android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
                android:layout_width="wrap_content" />

The height and width of my custom view doesnt seem to work. i have to
manualy hard code it to adjust and see my custom view using the bit of
code below located on my main activity class:

rssText = (ScrollingText) findViewById(R.id.rss);
rssText.setWidthHeight(200,50);

Code below is the ScrollingText methods.

Constructor:
        public ScrollingText(Context context, AttributeSet attrs) {
                super(context, attrs);

                textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
                textPaint.setColor(Color.BLACK);
                textBoxPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
                textBoxPaint.setColor(Color.WHITE);
                textPaint.setTextSize(20);




        }


public void setWidthHeight(int width, int height){
                this.height = height;
                this.width = width;
        }


        private void drawTextBox(Canvas c) {

                // TODO: Experiment with these co-ordinates
                c.drawRect(10, 0, width - 10, height, textBoxPaint);

        }

        private void drawTextRss(Canvas c) {
                int textHeight = (int) textPaint.getTextSize();
                printDebug("text height =  "+ textHeight);
                c.drawText(text, 10, height + 10, textPaint);
                //c.drawText("Hello, why doesnt this work????????????", 10, 50,
textPaint);
        }

        @Override
        protected void onDraw(Canvas canvas) {
                // TODO Auto-generated method stub
                super.onDraw(canvas);
                drawTextBox(canvas);
                drawTextRss(canvas);
                setVisibility(VISIBLE);
        }



        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{


                setMeasuredDimension(width,height);
                }

I hope my explanations and code is enough to help me figure out how i
can set the size of the custom view from the xml layout file.

Not sure why android:layout_height="wrap_content"
                android:layout_width="wrap_content" doesnt ??????

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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to