我想知道如何计算-webkit-device-pixel-ratio .我已经读过这个:http: //www.quirksmode.org/blog/archives/2012/06/devicepixelrati.html.但是我无法清楚地理解它.我还想知道是否有一个列表,哪些设备使用哪个像素比.安卓网站说
Android浏览器和WebView支持CSS媒体功能,允许您为特定屏幕密度创建样式 - -webkit-device-pixel-ratio CSS媒体功能.应用于此功能的值应为"0.75","1"或"1.5",以指示样式分别适用于具有低密度,中密度或高密度屏幕的设备.
但我发现我们需要使用-webkit-device-pixel-ratio = 2来使网络应用程序在768 x 1280分辨率屏幕上兼容.
我是Kotlin的新手,在LiveData观察方法中使用lambda表达式时感到有些困惑。
观察方法的签名如下
observe(LifecycleOwner owner, Observer<? super T> observer)
Run Code Online (Sandbox Code Playgroud)
其中Observer是具有单个方法的接口
void onChanged (T t)
Run Code Online (Sandbox Code Playgroud)
但是,按以下方式在kotlin中调用上述obtain方法会产生类型不匹配错误:
val myViewModel = ViewModelProviders.of(this).get(AnimeListViewModel::class.java)
myViewModel.animes.observe(this, { anime -> println(anime) })
Run Code Online (Sandbox Code Playgroud)
这与在视图上调用setOnClickListener不同吗?以下代码段完美运行,没有任何编译错误:
val myView = View(this)
myView.setOnClickListener { view -> println(view) }
Run Code Online (Sandbox Code Playgroud)
我已经阅读了这个答案,该答案显示了如何使用lambda表达式(使用SAM转换)调用该方法。但是,我仍然不确定为什么简单的箭头表达式会失败。
在下面的例子中,'this'用于初始化sinstance.
public class MyApplication extends Application
{
public static MyApplication sinstance;
@Override
public void onCreate()
{
super.onCreate();
sinstance=this;
}
Run Code Online (Sandbox Code Playgroud)
据我所知,'this'指的是对象的当前实例的引用.如果我错了,请纠正我.现在考虑以下程序
public static MyApplication sinstance;
@Override
public void onCreate()
{
super.onCreate();
sinstance=new MyApplication();
}
Run Code Online (Sandbox Code Playgroud)
new MyApplication用于实例化sinstance.那么为什么第二个程序在运行时崩溃,而第一个程序不会产生任何错误.它给出以下错误:
12-16 17:56:09.559 2156-2156/compdom.sad E/art: Throwing OutOfMemoryError "Failed to allocate a 10439248 byte allocation with 5527284 free bytes and 5MB until OOM"
12-16 17:56:09.559 2156-2156/compdom.sad E/AndroidRuntime: Error reporting crash
java.lang.OutOfMemoryError: Failed to allocate a 10439248 byte allocation with 5527284 free bytes …Run Code Online (Sandbox Code Playgroud) import java.io.*;
class empl
{
int p, n, r, i;
void accept()
{
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Principal amount");
int p = Integer.parseInt(br.readLine());
System.out.println("Enter no of years");
int n = Integer.parseInt(br.readLine());
System.out.println("Enter rate");
int r = Integer.parseInt(br.readLine());
} catch(Exception e)
{
System.out.println("" + e);
}
}
int calculate()
{
i = (p * n * r) / 100;
return (i);
}
}
class bank
{
public static void main(String args[])
{
empl e = new …Run Code Online (Sandbox Code Playgroud)