小编Vik*_*rya的帖子

角落处泄漏的涟漪效果,好像可按下按钮有一个 borderRadius

在参考了这个文档可按下文档后,我正在使用可按下作为按钮

现在我想为按钮添加涟漪效果,但它无法正常工作。

      <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

9
推荐指数
2
解决办法
3770
查看次数

如何设置反应材料用户界面的样式选择组件高度

我正在研究一个高度无法降低的选定组件。下面是截图

在此输入图像描述

我希望选择组件的高度与自动完成组件的高度相同,即项目级别

我可以通过检查在 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)

添加padding=8px后,问题暂时解决。 在此输入图像描述

问题代码存在于代码 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)

reactjs react-native material-ui

9
推荐指数
1
解决办法
1万
查看次数

kotlin 中的 sortBy - sortedBy 和 sortWith - sortedWith 有什么区别

我只是在探索 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操作。

任何人都可以用简单的语言对此进行解释。

kotlin

7
推荐指数
2
解决办法
2054
查看次数

kotlin中delay和Thread.sleep有什么区别

我试图弄清楚或证明“延迟如何暂停功能”。
所以,我在这里写了一个例子

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

kotlin kotlin-coroutines

7
推荐指数
3
解决办法
1万
查看次数

如何使用 kotlin 在内部存储中创建文件夹和文件


我正在尝试在我的清单中的内部存储上创建一个文件和文件夹

<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 教程。但没有一个起作用

java android kotlin nativescript flutter

6
推荐指数
1
解决办法
1万
查看次数

协程作用域构建器流程如何工作

科特林说

  • runBlocking 方法阻塞当前线程等待
  • coroutineScope 只是挂起,释放底层线程以供其他用途。
  • 因此 runBlocking 是一个常规函数,coroutineScope 是一个挂起函数
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)

在上面的例子中我期望的是:-

  • runBlocking 会阻塞主线程并launch执行它delay(200L)
  • 于是,底层协程被释放并运行,coroutineScope来到 …

kotlin kotlin-coroutines

4
推荐指数
1
解决办法
1762
查看次数

为什么 kotlin 中的属性覆盖使主构造函数属性为零

我正在尝试将值传递给构造函数并打印值。

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)

java inheritance constructor overriding kotlin

3
推荐指数
3
解决办法
557
查看次数

为什么 runBlocking 不会阻塞调用线程

我正在尝试了解 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)

科特林说

  1. runBlocking -Runs a new coroutine并且可blocks the current thread中断直到它完成
  2. 调用 runBlocking 的主线程会阻塞,直到 runBlocking 内的协程完成。

第 1 点:-如果 runBlocking 阻塞了main上面示例中的线程。然后在 runBlocking 中我如何main再次获得线程。

第 2 点:-如果Runs a new coroutine上面的语句为真,那么为什么它没有coroutine在 …

kotlin kotlin-coroutines

2
推荐指数
1
解决办法
1188
查看次数

为什么延迟会使 co 例程可以取消

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 kotlin-coroutines

1
推荐指数
1
解决办法
2220
查看次数

reactjs中如何让材质数据网格宽度填充父组件

我正在尝试显示所有列的数据网格应该采用相等的宽度以适合父组件。但是最后有一个空白空间,我无法删除它,也无法使列采用自动宽度以适应页面宽度。

任何人都可以帮我解决这个问题吗

https://codesandbox.io/s/musing-montalcini-tn04y

在此处输入图片说明

datagrid reactjs material-ui

1
推荐指数
2
解决办法
592
查看次数