Hi,
I think the issue is that you have not overridden onMeasure() method in your
custom view.
http://code.google.com/android/toolbox/custom-components.html#custom
When overriding this method, you *must* call setMeasuredDimension(int,
int)<http://code.google.com/android/reference/android/view/View.html#setMeasuredDimension%28int,%20int%29>to
store the measured width and height of this view. This way the parent
view will know how much width to allocate to this view in case you use
wrap_content.
When you don't do the steps above and specify WRAP_CONTENT for adding this
view to the parent view, the parent view does not know how much space to
allocate. So if you don't want to override onMeasure() in your custom view ,
don't use WRAP_CONTENT, use a specific dimension instead.
Thanks,
Megha
On Thu, Apr 10, 2008 at 11:03 AM, Android-Berry <[EMAIL PROTECTED]>
wrote:
>
> Hi There,
>
> I have created a simple custom view to display a line and added it to
> the LinearLayout.
>
> the custom view is displayed on Screen, the other view following the
> cusomview never show up on Screen.
>
> Thanks
>
> here is the code:
> from the code, I have added a CheckBox to LinearLayout after adding
> CustomView
>
>
>
>
> package android.test.custom;
>
> import android.app.Activity;
> import android.content.Context;
> import android.graphics.Canvas;
> import android.graphics.Color;
> import android.graphics.Paint;
> import android.os.Bundle;
> import android.view.View;
> import android.widget.CheckBox;
> import android.widget.LinearLayout;
> import android.widget.LinearLayout.LayoutParams;
>
> public class Test extends Activity {
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle icicle) {
> super.onCreate(icicle);
> //setContentView(R.layout.main);
> LinearLayout ll = new LinearLayout(this);
> ll.addView(new CustomView(this),new
> LinearLayout.LayoutParams(
> LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
> ll.setOrientation(LinearLayout.VERTICAL);
> ll.addView(new CheckBox(this),new LinearLayout.LayoutParams(
> LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
> setContentView(ll);
> }
> class CustomView extends View
> {
> public CustomView(Context ctx)
> {
> super(ctx);
> }
> /* (non-Javadoc)
> * @see android.view.View#onDraw(android.graphics.Canvas)
> */
> @Override
> protected void onDraw(Canvas canvas) {
> super.onDraw(canvas);
> canvas.save();
> Paint p = new Paint();
> p.setColor(Color.WHITE);
> canvas.drawLine(0, 0, 100, 0, p);
> canvas.restore();
> }
> }
> }
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---