在参考了这个文档可按下文档后,我正在使用可按下作为按钮
现在我想为按钮添加涟漪效果,但它无法正常工作。
<Pressable
android_ripple={{color: 'red', borderless: false}}
style={{backgroundColor: 'blue',borderRadius : 10}}>
<Text style={{alignSelf: 'center'}}>Button</Text>
</Pressable>
Run Code Online (Sandbox Code Playgroud)
如果按钮具有半径,则波纹效果没有边框半径。波纹效果角超出弯曲半径看起来很尴尬。
reactjs react-native react-native-android react-native-ios react-component
我正在研究一个高度无法降低的选定组件。下面是截图
我希望选择组件的高度与自动完成组件的高度相同,即项目级别
我可以通过检查在 HTML div 元素中添加、填充来实现这一点。但是,如何将该填充添加到组件中尚不清楚。这是我所添加的组件所看到的 HTML。
<div class="MuiInputBase-root MuiOutlinedInput-root" style="width: 300px;"><div class="MuiSelect-root MuiSelect-select MuiSelect-selectMenu MuiSelect-outlined MuiInputBase-input MuiOutlinedInput-input" tabindex="0" role="button" aria-haspopup="listbox" aria-labelledby="combo-box-demo" id="combo-box-demo" style="
padding: 8px; //**** here I have added padding to fix the issue ****
">a134</div>
...
...
...
Run Code Online (Sandbox Code Playgroud)
问题代码存在于代码 sanbox https://codesandbox.io/s/great-hill-ywql0?file=/App.js中
参考代码
import React from "react";
import "./styles.css";
import Select from "@material-ui/core/Select";
import MenuItem from "@material-ui/core/MenuItem";
import ListItemText from "@material-ui/core/ListItemText";
import Checkbox from "@material-ui/core/Checkbox";
import Autocomplete from "@material-ui/lab/Autocomplete";
import TextField from "@material-ui/core/TextField";
import Button from "@material-ui/core/Button"; …Run Code Online (Sandbox Code Playgroud) 我只是在探索 kotlin 集合,我观察到了一个重要的行为。
val sports = listOf<Sports>(
Sports("cricket", "7"),
Sports("gilli", "10"),
Sports("lagori", "8"),
Sports("goli", "6"),
Sports("dabba", "4")
)
sports.sortedBy { it.rating } // sortedByDescending is to sort in descending
.forEach({ println("${it.name} ${it.rating}") })
}
class Sports(name: String, rating: String) {
var name: String = name
var rating: String = rating
}
Run Code Online (Sandbox Code Playgroud)
上面我只能得到sortedBy方法,即以sorted. 我不知道为什么我没有得到sortBy和sortWith操作。
任何人都可以用简单的语言对此进行解释。
我试图弄清楚或证明“延迟如何暂停功能”。
所以,我在这里写了一个例子
var time: Long? = null
var job1 = GlobalScope.launch() {
println("Coroutine ${Thread.currentThread().name}")
time = measureTimeMillis {
Thread.sleep(1000)
println("After 1 seconds")
Thread.sleep(1000)
println("After 1 seconds")
Thread.sleep(1000)
println("After 1 seconds")
}
}
println("Thread ${Thread.currentThread().name}")
runBlocking {
job1.join()
println("Proccesed time is $time")
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是
Thread main
Coroutine DefaultDispatcher-worker-1
After 1 seconds
After 1 seconds
After 1 seconds
Proccesed time is 3015
Run Code Online (Sandbox Code Playgroud)
然后我替换Thread.sleep为delay,处理时间仍然是3045 ms。
我没有发现Thread.sleep与 之间有什么区别delay。
如何证明它是aSuspending Function且不同于Thread.sleep
我正在尝试在我的清单中的内部存储上创建一个文件和文件夹
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Run Code Online (Sandbox Code Playgroud)
这些权限。
fun test(view: View) {
try {
val myObj = File("filename.txt")
if (myObj.createNewFile()) {
println("File created: " + myObj.name)
} else {
println("File already exists.")
}
} catch (e: IOException) {
println("An error occurred.")
e.printStackTrace()
}
}
}
Run Code Online (Sandbox Code Playgroud)
我懂了
An error occurred.
java.io.IOException: Read-only file system
Run Code Online (Sandbox Code Playgroud)
我尝试了很多其他东西,从 javatpoint 到官方 java 和 kotlin 教程。但没有一个起作用
科特林说
fun main() = runBlocking { // this: CoroutineScope
launch {
delay(200L)
println("Task from runBlocking")
}
coroutineScope { // Creates a coroutine scope
launch {
delay(500L)
println("Task from nested launch")
}
delay(100L)
println("Task from coroutine scope") // This line will be printed before the nested launch
}
println("Coroutine scope is over") // This line is not printed until the nested launch completes
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中我期望的是:-
launch执行它delay(200L)coroutineScope来到 …我正在尝试将值传递给构造函数并打印值。
open class Car(c: Int){
open var cost: Int = c
init {
println("This comes First $cost")
}
}
open class Vehicle(cc: Int) : Car(cc) {
override var cost: Int = 20000
init {
println("This comes Second $cost")
}
fun show(){
println("cost = $cost")
}
}
fun main() {
var vehicle = Vehicle(1000)
vehicle.show()
}
Run Code Online (Sandbox Code Playgroud)
输出
This comes First 0
This comes Second 20000
cost = 20000
Run Code Online (Sandbox Code Playgroud)
如果我只是评论这一行
override var cost: Int = 20000
输出将是
This comes First 1000
This …Run Code Online (Sandbox Code Playgroud) 我正在尝试了解 kotlin 中的 runBlocking。
println("before runBlocking ${Thread.currentThread().name}")
runBlocking { // but this expression blocks the main thread
delay(2000L) // non blocking
println("inside runBlocking ${Thread.currentThread().name}")
delay(2000L)
}
println("after runBlocking ${Thread.currentThread().name}")
Run Code Online (Sandbox Code Playgroud)
输出
before runBlocking main
inside runBlocking main
after runBlocking main
Run Code Online (Sandbox Code Playgroud)
科特林说
- runBlocking -
Runs a new coroutine并且可blocks the current thread中断直到它完成- 调用 runBlocking 的主线程会阻塞,直到 runBlocking 内的协程完成。
第 1 点:-如果 runBlocking 阻塞了main上面示例中的线程。然后在 runBlocking 中我如何main再次获得线程。
第 2 点:-如果Runs a new coroutine上面的语句为真,那么为什么它没有coroutine在 …
fun main() = runBlocking {
var i = 1
var job = launch (Dispatchers.Default){
println("Thread name = ${Thread.currentThread().name}")
while (i < 10) { // replace i < 10 to isActive to make coroutine cancellable
delay(500L)
// runBlocking { delay(500L) }
println("$isActive ${i++}")
}
}
println("Thread name = ${Thread.currentThread().name}")
delay(2000L) // delay a bit
println("main: I'm tired of waiting!")
job.cancelAndJoin() // cancels the job and waits for its completion
println("main: Now I can quit.")
}
Run Code Online (Sandbox Code Playgroud)
输出
Thread name = main
Thread …Run Code Online (Sandbox Code Playgroud) 我正在尝试显示所有列的数据网格应该采用相等的宽度以适合父组件。但是最后有一个空白空间,我无法删除它,也无法使列采用自动宽度以适应页面宽度。
任何人都可以帮我解决这个问题吗
kotlin ×7
reactjs ×3
java ×2
material-ui ×2
react-native ×2
android ×1
constructor ×1
datagrid ×1
flutter ×1
inheritance ×1
nativescript ×1
overriding ×1