Good day to all. I want to raise my level and learn how to make custom views. I thought at first to take TabLayout and simply override the onDraw method, onDraw say, but immediately ran into a problem (most likely a lack of knowledge). In general, the problem is that after inheriting and redefining the onDraw method in my class (MyTabLayout), I want all the other methods of the super class (TabLayout) to remain as they were, so what is my joint and how to do it? P.S. Sorry for the stupid question.

  */ public class MyTabLeyout extends TableLayout { private int mIndicatorLeft = -1; private int mIndicatorRight = -1; private int mSelectedIndicatorHeight; private final Paint mSelectedIndicatorPaint; private static final Pools.Pool<TabLayout.Tab> sTabPool = new Pools.SynchronizedPool<>(16); private final ArrayList<TabLayout.Tab> mTabs = new ArrayList<>(); public MyTabLeyout(Context context, Paint mSelectedIndicatorPaint) { super(context); this.mSelectedIndicatorPaint = new Paint(); } public int getTabCount() { return mTabs.size(); } private void setIndicatorPosition(int left, int right) { if (left != mIndicatorLeft || right != mIndicatorRight) { // If the indicator's left/right has changed, invalidate mIndicatorLeft = left; mIndicatorRight = right; ViewCompat.postInvalidateOnAnimation(this); } } void setSelectedIndicatorColor(int color) { if (mSelectedIndicatorPaint.getColor() != color) { mSelectedIndicatorPaint.setColor(color); ViewCompat.postInvalidateOnAnimation(this); } } void setSelectedIndicatorHeight(int height) { if (mSelectedIndicatorHeight != height) { mSelectedIndicatorHeight = height; ViewCompat.postInvalidateOnAnimation(this); } } @Override public void draw(Canvas canvas) { super.draw(canvas); // Thick colored underline below the current selection if (mIndicatorLeft >= 0 && mIndicatorRight > mIndicatorLeft) { canvas.drawCircle(mIndicatorLeft,getHeight() - mSelectedIndicatorHeight,10,mSelectedIndicatorPaint); // canvas.drawRect(mIndicatorLeft, getHeight() - mSelectedIndicatorHeight, // mIndicatorRight, getHeight(), mSelectedIndicatorPaint); } } } 

Closed due to the fact that the participants are not on topic : ♦ , aleksandr barakin , zRrr , user194374, D-side 27 Mar '16 at 21:57 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Yuriy SPb, aleksandr barakin, zRrr, Community Spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Well ... So redefine only the necessary method and everything ... Delete the rest ... - YuriySPb ♦
  • @Yuriy SPb, so after if I refer to methods from my created class from another class, they are not "visible" final MyTabLeyout tabLayout = (MyTabLeyout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText("VIDEOS")); final MyTabLeyout tabLayout = (MyTabLeyout) findViewById(R.id.tab_layout); tabLayout.addTab(tabLayout.newTab().setText("VIDEOS")); in that case, addTab && newTab does not define methods - Diha-o
  • I do not know what your problem is. I've just expanded the class from TabLeyout by redefining the minimal + onDraw constructor. And all the methods listed by you, as expected, are quite visible to yourself. - Yuriy SPb ♦
  • @Yuriy SPb, re: redefining the minimal constructor, what do you mean ??? - Diha-o
  • I mean the designer with one argument - a context. - YurySPb ♦

1 answer 1

You are just sealed. You wanted to expand TabLayout , and expanded TableLayout .

Be careful)

  • And in the name of your class sealed. It is better not to write code at night))) - YuriySPb ♦
  • 2
    oh god ahahha Right now I sit in my laughter, I laugh .. all the same at night sometimes it is better to sleep)) Thank you very much) - Diha-o