Nine patches in a custom viewing group

I made nine patches and a custom viewing group, then I made the background of this group of views for the ninth patch.

The problem is that nine patches ignore the "content area" settings.

So: how do I use nine patches correctly in the user view?

OR

How to grab a nine-patch content area so that I can use it in OnMeasure and OnLayout math?

+4
source share
3 answers

Also use boolean getPadding (Rect padding) in NinePatchDrawable to get padding for content (your content + 9patch padding = general group)

+6
source

You may need to draw the object directly into the ViewGroup by overriding its onDraw method:

public void onDraw(Canvas canvas) { NinePatchDrawable bg = (NinePatchDrawable) resources.getDrawable(id); if (bg != null) { bg.setBounds(0, 0, getWidth(), getHeight()); bg.draw(canvas); } } 
0
source

Get the background padding in your onMeasure to reduce the available width (this is to highlight cells in the grid):

  @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Drawable background = getBackground(); Rect padding = new Rect(); if (background != null && background.getPadding(padding)); int width = MeasureSpec.getSize(widthMeasureSpec); int availableWidth = width - padding.left - padding.right; 

And for onLayout, the add-on is applied:

  @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { int availableWidth = r - l - getPaddingLeft() - getPaddingRight(); 
0
source

All Articles