如果我想使用$
登录多行字符串,我该如何逃避呢?
val condition = """ ... $eq ... """
Run Code Online (Sandbox Code Playgroud)
$eq
被解析为对变量的引用.如何逃避$
,以便它不会被识别为变量的引用?(Kotlin M13)
我遇到了一个问题,RecyclerView
当它是ConstraintLayout
. 最初,它RecyclerView
位于Relative-
、Frame-
和LinearLeayout
s的视图层次结构深处,并且一切正常,直到我决定使用 ConstraintLayout 扁平化视图树。我注意到每次由于任何原因(窗口调整大小、数据集更改通知等)导致布局更改时, 的滚动位置RecyclerView
都会更改。
例如,每次我显示和隐藏软键盘时,内容回收器视图都会漂移一定的像素。
我能够在一个非常简单的布局上重现这种行为:
ConstraintLayout
|---RecyclerView
|---Button
|---EditText
Run Code Online (Sandbox Code Playgroud)
如果我将约束设置RecyclerView
为放置在 的任何其他子项之上ConstraintLayout
(意味着 RecyclerView 具有底部约束),并且如果我使用LinearLayoutManager
with reverseLayout = true
,我可以重现上述行为。
我应该如何解决这个问题(我不想改变滚动位置)?也许 RecyclerView 和/或 ConstraintLayout 上有一些我不知道的标志......
这是我的layout.xml
:
ConstraintLayout
|---RecyclerView
|---Button
|---EditText
Run Code Online (Sandbox Code Playgroud)
这里是代码设置RecyclerView
在Activity.onCreate()
:
setContentView(R.layout.activity_main)
val adapter = Adapter()
val layoutManager = LinearLayoutManager(this)
layoutManager.orientation = LinearLayoutManager.VERTICAL
layoutManager.reverseLayout = true
val recycler = findViewById<RecyclerView>(R.id.recycler)
recycler.layoutManager = layoutManager …
Run Code Online (Sandbox Code Playgroud) 我Observable.create()
用来创建一个observable来对调度程序执行一些工作(例如Schedulers.io()
,然后返回结果)AndroidSchedulers.mainThread()
.
val subscription = observable<T> {
try {
// perform action synchronously
it.onNext(action.invoke(context, args))
it.onCompleted()
} catch (t: Exception) {
it.onError(t)
}
}.subscribeOn(scheduler)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
// handle result here
result.set(it)
},
{
// handle error here
errorHandler.handleTaskError(model, this, it)
},
{
// notify completed
model.completeTask(this)
}
)
Run Code Online (Sandbox Code Playgroud)
内部操作action.invoke()
是同步的,可能是阻塞IO操作.当用户决定取消它时,我取消订阅observable:subscription.unsubscribe()
但是,I/O操作不会被中断.是否有任何rx-java API来中断操作?
我正在使用Android Studio并且有几个依赖于相同代码的应用程序.我将共享代码移动到一个单独的库中,以便将其包含在我的应用程序中.
我为此目的创建的库项目(MyLib)需要一个jar文件来编译,所以我将它添加到项目的libs目录中.
我build.gradle
的MyLib主模块如下所示:
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.android"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
}
}
}
dependencies {
compile files('./libs/external-java-lib.jar')
}
Run Code Online (Sandbox Code Playgroud)
当我构建项目时,gradle会生成一个包含的jar文件external-java-lib.jar
.
我希望我的Android应用程序项目提供"external-java-lib.jar",而不是MyLib.因为在我的应用程序中我可能会使用不同版本的external-java-lib.jar
.
如何配置Gradle以external-java-lib.jar
从我的库项目的构建中排除?
我在网上找不到我的问题的答案,所以我觉得我想要的是一个糟糕的设计.我还可以做些什么?
先感谢您.