@Composable
fun PreviewLayout() {
fun getRandomString(length: Int): String {
val allowedChars = ('A'..'Z') + ('a'..'z') + ('0'..'9')
return (1..length)
.map { allowedChars.random() }
.joinToString("")
}
val horizontalScrollState = rememberScrollState()
LazyColumn(
modifier = Modifier
.background(Color.Blue)
.fillMaxHeight()
.wrapContentWidth()
.horizontalScroll(horizontalScrollState)
) {
items(5) { index ->
Text(
text = getRandomString((index + 1) * 4).uppercase(),
color = Color.Black,
fontSize = 16.sp,
modifier = Modifier
.padding(8.dp)
.background(Color.Yellow)
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
布局预览:
我希望项目的宽度与列表中最大项目的宽度相同。
请注意.horizontalScroll(horizontalScrollState),这是为了允许水平滚动。
我想要什么:
我需要使用 aLazyColumn但如果我可以使用 aColumn我会这样写:
Column( …Run Code Online (Sandbox Code Playgroud) 我有一个使用回收视图的ListView.我试图阻止视图回收.所以我使用setHasTransientState:
android.support.v4.view.ViewCompatJB.setHasTransientState(View view,boolean hasTransientState)
它在Jellybean版本上工作得非常好,但它在Api <16上没有做任何事情.有没有办法使它工作或者有不同的方法用于预先豆豉?
我发现了如何设置像@Daniel Chow建议的RecyclerListener .
listView.setRecyclerListener(new RecyclerListener() {
@Override
public void onMovedToScrapHeap(View view) {
// Stop animation on this view
}
});
Run Code Online (Sandbox Code Playgroud) java android android-animation android-listview android-support-library
由于appcompat v7缺失了SwitchCompatPreference,似乎有必要自己创建它.
怎么能实现这一目标?我google了一下,找到了一个教程DialogPreference.我试图采用它,SwitchCompatPreference但在我的xml布局中,它总是说在偏好xml中不允许这个类.
我需要做什么?
我有一个带有填充的可滚动EdiText,但是如您所知,当您在EditText中滚动文本时,它会被填充剪掉,而不是重叠。
EditText没有clipToPadding选项。是否有一种方法可以模仿ViewGroup中可用的clipToPadding =“ false”功能?
android textview android-layout android-edittext android-view
将此 RxJava 链转换为 Kotlin 协程的最佳方法是什么?
RxTextView
.textChanges(inputEditText)
.map { it.toString() }
.throttleLatest(500, TimeUnit.MILLISECONDS, true)
.distinctUntilChanged()
.subscribe({ text ->
// More logic here
}, { error ->
// Error handling
})
Run Code Online (Sandbox Code Playgroud) 我尝试从自动完成列表中排除kotlin.Result,但即使在使缓存无效之后也无法正常工作。它适用于普通班。
我遵循了这份官方指南https://www.jetbrains.com/help/idea/auto-completing-code.html#configure-code-completion
有没有什么办法解决这一问题 ?
我有一个 Google 文档,其中包含一张图像。我发现图像objectId如下所述https://developers.google.com/docs/api/reference/rest/v1/InlineObject但我无法理解如何获取该图像的网址。我尝试在云端硬盘中搜索此内容objectId,但它返回File not found。
有任何想法吗 ?
更新
正如 @Tanaike 所指出的,图像信息包含在 中result.inlineObjects,而不是直接包含在段落中。
我正在尝试在我的应用程序项目中包含v7 recyclerview库.
我按照以下步骤https://developer.android.com/tools/support-library/setup.html#add-library
我采用进口V7 recyclerview库导入现有的Android代码导入工作区 和包括 ndroid支持-V7-recyclerview.jar 文件添加到构建路径.
但是当我在单击添加按钮后尝试将库包含到我的项目中时,没有要包含的库:
从Android开发人员站点:
将库添加到您的应用程序项目:
在Project Explorer中,右键单击项目,然后选择"属性".
在对话框左侧的类别面板中,选择Android.
我正在尝试在我的Android项目中添加一个资源文件夹.我创建了一个新的文件夹extra-res所以我的项目结构如下所示:
+ src
+ main
+ res
+ layout
+ ...etc...
+ extra-res
+ layout
Run Code Online (Sandbox Code Playgroud)
所以我把它添加到build.gradle:
android {
.........
sourceSets {
main {
res.srcDirs = ['res', 'extra-res']
}
}
}
Run Code Online (Sandbox Code Playgroud)
但在编辑build.gradle文件后,构建失败.
:app:processDebugResources C:\ Users\vovasoft\AndroidStudioProjects\sdbm\app\build\intermediates\manifests\full\debug\AndroidManifest.xml
错误:(13,23)找不到与给定名称匹配的资源(在'icon'处值为'@ drawable/ic_launcher').
错误:(14,24)找不到与给定名称匹配的资源(在'label'处,值为'@ string/app_name').错误:任务':app:processDebugResources'的执行失败.com.android.ide.common.internal.LoggedErrorException:无法运行命令:
aapt.exe包-f --no-crunch -I android.jar -M\AndroidStudioProjects\sdbm\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S\AndroidStudioProjects\sdbm\app\build\intermediates\res\debug -A\AndroidStudioProjects\sdbm\app\build\intermediates\assets\debug -m -JC:\ Users\vovasoft\AndroidStudioProjects\sdbm\app\build\generated\source\r\_spid -F('label'的值为'@ string/activity_edit_field').
在编辑build.gradle之前,构建成功.
我如何使用它并为其添加过期时间,这意味着如果流中存在相同的值,我们仍然会收集它,因为在发出前一个重复值之后distinctUntilChanged()它的时间超过了毫秒。expiry
flow {
emit("A") // printed
emit("B") // printed
emit("A") // printed
emit("A") // NOT printed because duplicate
delay(5000)
emit("A") // printed because 5 seconds elapsed which is more than expiry
}
.distinctUntilChanged(expiry = 2000)
.collect {
println(it)
}
Run Code Online (Sandbox Code Playgroud)
我想打印这个:
A
B
A
A
Run Code Online (Sandbox Code Playgroud)
这是测试它的代码:
@Test
fun `distinctUntilChanged works as expected`(): Unit = runBlocking {
flow {
emit("A") // printed
emit("B") // printed
emit("A") // printed
emit("A") // NOT printed because duplicate
delay(5000)
emit("A") // printed because …Run Code Online (Sandbox Code Playgroud) android ×6
kotlin ×3
android-view ×1
eclipse ×1
java ×1
kotlin-flow ×1
preference ×1
rx-java2 ×1
switchcompat ×1
textview ×1