I create a View. LinearLayout with horizontal dots in it (navigation points for the ViewFlipper). The selected item is tinted orange, not cut white. To start, create a point. The dot has a base color and a black stroke.

public class NewCircleView extends View { Paint mainPaint; Paint outerPaint; int cx; int cy; int r; public NewCircleView(Context context, int diameter) { super(context); setMinimumWidth(diameter); setMinimumHeight(diameter); r = cy = cx = diameter / 2; setMainParams(); } public NewCircleView(Context context, AttributeSet attrs) { super(context, attrs); int[] attrsArray = new int[] { android.R.attr.layout_width, android.R.attr.layout_height }; TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray); cx = ta.getDimensionPixelSize(0, ViewGroup.LayoutParams.MATCH_PARENT); cy = ta.getDimensionPixelSize(1, ViewGroup.LayoutParams.MATCH_PARENT); cx = cx /2; cy = cy /2; r = cx > cy ? cy : cx; ta.recycle(); setMainParams(); } public void switchColorToWhite() { mainPaint.setColor(Decorator.WHITE); invalidate(); } public void switchColorToOrange() { mainPaint.setColor(Decorator.ORANGE); invalidate(); } public void setColor(int color) { mainPaint.setColor(color); invalidate(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(cx, cy,r,outerPaint); canvas.drawCircle(cx, cy,r-2,mainPaint); } private void setMainParams() { mainPaint = new Paint(); mainPaint.setColor(Decorator.WHITE); outerPaint = new Paint(); outerPaint.setColor(Decorator.BLACK); } } 

Next we need a layer where we will place these points. This should be done dynamically, since there can be a different number of slides for the ViewFlipper.

 public class DotBar extends LinearLayout { ArrayList<NewCircleView> dots = new ArrayList<>(); public DotBar(Context context, int dotsCount) { super(context); setOrientation(HORIZONTAL); setLayoutParams(new LinearLayout.LayoutParams(Decorator.LLWC, Decorator.LLWC)); for (int i = 0; i < dotsCount; i++) { dots.add(new NewCircleView(context, Decorator.dipToPx(8))); } for (NewCircleView dot : dots) { addView(dot); invalidate(); } } public void setPosition(int position) { for (int i = 0; i < dots.size(); i++) { if (i == position) dots.get(position).switchColorToOrange(); else dots.get(i).switchColorToWhite(); } } } 

The essence of the question is this. When I add CircleView on DotView, despite the fact that Orientation is set for me, I still get layered points on each other. In my case, I pass to dotsCount 5, and add DotBar to the layer with ViewFlipper, but on the layer with ViewFlipper I see not 5 points, but only one.

Actually the code that adds the dotbar

  mainView = inflater.inflate(R.layout.main_fragment, container, false); RelativeLayout layout = (RelativeLayout) mainView.findViewById(R.id.parent); dotBar = new DotBar(getActivity(), Data.slides.size()); layout.addView(dotBar); 

C creating my own View I am not very experienced, could make some kind of basic error. Help please solve the problem.

  • and can you make a point through the resources? for example through shapes or generally two png pictures - andreich
  • It is more pleasant for me to clog the code than to clog the resources, purely subjectively :) The point is perfectly drawn and so, there are no problems with it. The problem is that several View are incorrectly added to LinearLayout - iamthevoid
  • one
    But try adding the usual ones instead of this twist to limit your search a bit - andreich
  • There are no problems with the text, it is added, as expected, to the line. - iamthevoid
  • WHAT something tells me that my view size is 0, and therefore it is added to one place - iamthevoid

0