Android: Why can't I override setFrame from view?

Just try expanding the view and doing some special work, but Eclipse will complain when I try to override the setFrame method. The statement that there is no method to override in the parent class:

The setFrame (int, int, int, int, int) method of type Test must override or implement the supertype method

Here is the signature of the method from the source SDK for Android.

protected boolean setFrame(int left, int top, int right, int bottom) 

As you can see, this is not a private or batch level, or even specified as final ... just protected. This should mean that I can completely override it in a subclass. Right? Below is the minimum size of what I'm trying to do in Eclipse. This might just be an Eclipse bug, but I'm not too familiar with Ant to check this out.

Edit: For those who answer that setFrame is not defined in the View class, I can assure you. How else do you think I have a method signature? It is even called during layout (). Or am I seriously just crazy?

git HEAD: View.java
Cupcake (1.5r4): View.java

You can even see that the method is overridden in ImageView and TextView ... so I am seriously confused about why I cannot override it directly from the view directly ...

 public class Test extends View { public Test(Context context) { super(context); } public Test(Context context, AttributeSet attrs) { super(context, attrs); } public Test(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected boolean setFrame(int left, int top, int right, int bottom) { return super.setFrame(left, top, right, bottom); } } 
+4
source share
2 answers

According to the documentation, setFrame not defined in the View class (not strictly true - see editing). Surprisingly, each subclass of TextView and ImageView defines it themselves. You will need to extend a specific subclass for each widget that you want to override. This is based on documents for Android 2.3 r1 - 05 Jan 2011 12:43 .

See documentation:

Classes That Define SetFrame
http://www.google.com/search?q=site:developer.android.com+%22boolean+setFrame%22

TextView and ImageView .

Edit:

As the OP points out in the comments, the method is clearly defined in the source code of View.java . However, the documentation acts as if this method were not defined there.

The reason for this is that the setFrame () method in View has the @hide Javadoc tag:

 /** * Assign a size and position to this view. * * This is called from layout. * * @param left Left position, relative to parent * @param top Top position, relative to parent * @param right Right position, relative to parent * @param bottom Bottom position, relative to parent * @return true if the new size and position are different than the * previous ones * {@hide} */ protected boolean setFrame(int left, int top, int right, int bottom) { 

This seems to hide the method from Javadoc:

http://www.androidjavadoc.com/?p=63

Particular attention should be paid to the @hide tag, which the standard doclet interpreter interprets and which hides the source without the SDK, and therefore this code should not be used in applications .

Is it possible that the reason it cannot be overridden is because the Eclipse plugin for Android or the Android compiler somehow uses the @hide tag? I dont know.

+4
source

Since setFrame is not defined in the View Class

+1
source

Source: https://habr.com/ru/post/1336378/


All Articles