Skip to content Skip to sidebar Skip to footer

Custom View Not Displayed Well In Android

My custom view does not display entirely. Please see my screenshot: And the source code package com.dots; import android.graphics.Color; import android.app.Activity; import androi

Solution 1:

Making the assumption that you don't want the clipping you see in your screenshot. Your problem is that the values you return in onMeasure don't account for your x, y offsets:

protectedvoidonMeasure(int widthMeasureSpec, int heightMeasureSpec){
    super.onMeasure(View.MeasureSpec.makeMeasureSpec(Constants.DOTS_RADIUS*2 + x, View.MeasureSpec.EXACTLY),
           View.MeasureSpec.makeMeasureSpec(Constants.DOTS_RADIUS*2 + y, View.MeasureSpec.EXACTLY));
}

Solution 2:

What exactly do you want to Achieve? if you want to be fullscreen then use the FILL_PARENT flag instead of WRAP_CONTENT at least for the width of your view. also for the height there is a weight parameter that might help even the height of your view. but since its a custom drawing i cant help you further if there are any adjustments needed in your view code. you have to figure that out for yourself.

Solution 3:

The radius of each of your "dots" is identical, and this directly translates into the answer you return in onMeasure(). You're changing the x and y location of the center, getting further from the actual View canvas.

Post a Comment for "Custom View Not Displayed Well In Android"