Android 如何使接口方法成为Kotlin的内部方法?

Android 如何使接口方法成为Kotlin的内部方法?,android,kotlin,Android,Kotlin,我编写了一个简单的SwipeLayout库。我的目标是通过GitHub发布,供包括我在内的所有人使用。 当我决定封装一些方法时,遇到了一个问题。我希望有一个内部修饰符来解决这个问题,但是我找不到一个合适的方法来解决这个问题。 以下是一些代码和说明: class SwipeLayout (...) : FrameLayout(...), BackgroundViewsVisibilityController, ... { private val backgroundControlle

我编写了一个简单的SwipeLayout库。我的目标是通过GitHub发布,供包括我在内的所有人使用。 当我决定封装一些方法时,遇到了一个问题。我希望有一个内部修饰符来解决这个问题,但是我找不到一个合适的方法来解决这个问题。 以下是一些代码和说明:

class SwipeLayout (...) : FrameLayout(...),
  BackgroundViewsVisibilityController, ... {
  
  private val backgroundController = BackgroundController(
        this //(BackgroundViewsVisibilityController)  
  )

  override fun revealLeftUnderView() {...}

  override fun hideLeftUnderView() {...}

  override fun revealRightUnderView() {...}

  override fun hideRightUnderView() {...}
}


interface BackgroundViewsVisibilityController {
   fun revealLeftUnderView()
   fun revealRightUnderView()
   fun hideLeftUnderView()
   fun hideRightUnderView()
}

这些是对用户隐藏的方法。如何才能最好地实现它?

internal
告诉编译器只能从当前模块调用此接口、类或函数。释放库时,无法从库中调用
内部
接口(不使用反射)

您希望将
SwipeLayout
公开(供第三方使用),因此不能同时将接口
BackgroundViewsVisibilityController
内部
,因为您的类正在扩展该接口

如果您真的希望客户端不能从接口调用函数,请考虑没有接口(通常是用于调用方的接口),而使这些函数<代码>私有< /代码>在<代码> SwitelayOuts< /C> >:

class SwipeLayout(…):框架布局(…)
私人娱乐revealLeftUnderView(){…}
私人娱乐隐藏视图(){…}
私人娱乐revealRightUnderView(){…}
私人娱乐隐藏视图(){…}
}

有关内部

的详细信息告诉编译器只能从当前模块调用此接口、类或函数。释放库时,无法从库中调用
内部
接口(不使用反射)

您希望将
SwipeLayout
公开(供第三方使用),因此不能同时将接口
BackgroundViewsVisibilityController
内部
,因为您的类正在扩展该接口

如果您真的希望客户端不能从接口调用函数,请考虑没有接口(通常是用于调用方的接口),而使这些函数<代码>私有< /代码>在<代码> SwitelayOuts< /C> >:

class SwipeLayout(…):框架布局(…)
私人娱乐revealLeftUnderView(){…}
私人娱乐隐藏视图(){…}
私人娱乐revealRightUnderView(){…}
私人娱乐隐藏视图(){…}
}
更多关于