我正在关注一个Android编程视频讲座系列,它是在API之前设计的21次.因此它告诉我以下面的方式创建一个SoundPool变量.
SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
//SoundPool(int maxStreams, int streamType, int srcQuality)
Run Code Online (Sandbox Code Playgroud)
但是,我也希望将此SoundPool用于API 21.所以,我这样做:
if((android.os.Build.VERSION.SDK_INT) == 21){
sp21 = new SoundPool.Builder();
sp21.setMaxStreams(5);
sp = sp21.build();
}
else{
sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
}
Run Code Online (Sandbox Code Playgroud)
sp21是Builder
API 21 的类型变量,sp是SoundPool
类型的变量.
这与我的具有API 21的AVD和具有API 19的真实设备非常适用.(没有尝试使用具有API 21的真实设备但我认为它将工作良好).现在,我想在之前将if 设置为streamType
to .所以我键入:USAGE_MEDIA
sp = sp21.build();
sp21.setAudioAttributes(AudioAttributes.USAGE_MEDIA);
Run Code Online (Sandbox Code Playgroud)
但是Lint用红色标记它说:
SoundPool.Builder类型中的方法setAudioAttributes(AudioAttributes)不适用于参数(int)
我知道即使我没有将它设置为USAGE_MEDIA,它默认也会设置为相同.但是我要求将来参考,如果我必须将它设置为其他类似的东西:USAGE_ALARM.
我该怎么办?
请帮忙!
如果我想让我的TextView宽度完全等于其父级的宽度,我可以使用
android:layout_width="fill_parent"
Run Code Online (Sandbox Code Playgroud)
如果我想把它放到零件宽度的一半呢?或者,通常,设置相对于父宽度的宽度?
编辑:我正在使用相对布局
我的屏幕看起来像这样.
那里有许多Eclipse版本.例如:靛蓝,朱诺,开普勒,月神,火星.哪些最适合ADT?Stack Overflow上有很多这样的问题,但它们都是4-5岁.我正在寻找更新的东西.
在Java中,我除以零,这显然不会产生数字.
public class tempmain {
public static void main(String args[])
{
float a=3/0;
System.out.println(a);
}
}
Run Code Online (Sandbox Code Playgroud)
我希望输出为"NaN",但它显示以下错误:
Exception in thread "main" java.lang.ArithmeticException: / by zero
at tempmain.main(tempmain.java:6)
Run Code Online (Sandbox Code Playgroud)
是否有任何方式(除此之外if(denominator==0)
)可以显示NaN?