2013-10-04 77 views
1

我是Android和Java的新手,不理解某些东西。 View类中有公共方法,其前缀为@ViewDebug.ExportedProperty(category = "layout")。例如:无法调用ViewDebug.ExportedProperty方法

@ViewDebug.ExportedProperty(category = "layout") 
public boolean isLayoutRtl() { 
    return (getLayoutDirection() == LAYOUT_DIRECTION_RTL); 
} 

为什么来自View派生的Android类可以调用这些公共方法,但类在另一个包(如矿)也从View派生,也看不出这些公共的方法呢?

回答

0

检查整个方法,包括评论。

/** 
* Indicates whether or not this view's layout is right-to-left. This is resolved from 
* layout attribute and/or the inherited value from the parent 
* 
* @return true if the layout is right-to-left. 
* 
* @hide 
*/ 
@ViewDebug.ExportedProperty(category = "layout") 
public boolean isLayoutRtl() { 
    return (getLayoutDirection() == LAYOUT_DIRECTION_RTL); 
} 

有一个@hide注解,这意味着该方法不使用公共的Android API的一部分。

幸运的是,方向常数和getLayoutDirection()已经公开。在你自己的实现中复制这个方法是微不足道的。

0

我发现一些前缀为@hide的公共方法,但派生自View的Android类可以调用这些公共方法。例如:

/** 
* Returns whether this View is accessibility focused. 
* 
* @return True if this View is accessibility focused. 
* @hide 
*/ 
public boolean isAccessibilityFocused() { 
    return (mPrivateFlags2 & PFLAG2_ACCESSIBILITY_FOCUSED) != 0; 
} 

我是一个Android和Java初学者。