我有一个应用程序来管理每个对象与一个类关联的对象,并且具有在一天的特定时间执行命令的顺序,例如一次在上午9点,另一个在下午2点.我的问题是:在java中只处理时间的最佳方法是什么?我正在使用日历和时间课程,但我必须强制要求年,月,日,这对我来说是无法使用的数据.我的帐户通过处理日期的对象操纵事件计划并不是最佳的,那么我可以这样做吗?
在 Canvas 中,用 RectF 绘制一个矩形,需要在 dp 或 px 中设置 top 和 left 吗?
Integer padding = 10;
Integer width = 100; // It is dp or px?
Integer height = 50;
RectF position = new RectF();
position.top = 0 + padding;
position.bottom = position.top + height;
position.left = 0 + padding;
position.right = position.left + width;
Run Code Online (Sandbox Code Playgroud)
http://developer.android.com/intl/es/reference/android/graphics/RectF.html 它不指示值是以 px 还是 dp 表示。
我在这个布局上遇到了问题:(
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cuerpo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical" >
...
Run Code Online (Sandbox Code Playgroud)
在java代码中
LinearLayout cuerpo = (LinearLayout) findViewById(R.id.cuerpo);
if(align){
cuerpo.setGravity(Gravity.CENTER_VERTICAL);
}else{
cuerpo.setGravity(Gravity.NO_GRAVITY);
}
Run Code Online (Sandbox Code Playgroud)
我需要layout_gravity没有引力.
我用的是一个ProgressBar在xml的Android总线上很慢.最佳是60fps.是否可以更改帧速率或添加更多fps的自定义进度圈?
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="17dp"
android:layout_gravity="center" />
Run Code Online (Sandbox Code Playgroud) 有这个:
DATABASE_HOST=[ $# -le 3 ] && $3 || '127.0.0.1';
Run Code Online (Sandbox Code Playgroud)
但不起作用。是一个带有 3 个可选参数的 bash 脚本:
db.sh user dbname hostname
Run Code Online (Sandbox Code Playgroud)
我想替换我的旧方法:
if [ $# -le 3 ]
then
DATABASE_HOST=$3;
else
DATABASE_HOST='127.0.0.1';
fi
Run Code Online (Sandbox Code Playgroud) 如何获取子类的文件名?
例子:
base.py:
class BaseClass:
def __init__(self):
# How to get the path "./main1.py"?
Run Code Online (Sandbox Code Playgroud)
main1.py:
from base import BaseClass
class MainClass1(BaseClass):
pass
Run Code Online (Sandbox Code Playgroud) 有这个代码:
string abc = "123456";
Run Code Online (Sandbox Code Playgroud)
要转换为int,我应该使用convert:
int abcInt = Convert.ToInt32(abc);
Run Code Online (Sandbox Code Playgroud)
问题是,如果不是数字我有一个例外,看到返回零,所以我的最终代码将如下所示:
try{ int abcInt = Convert.ToInt32(abc); }catch(Exception e){ int abcInt = 0; }
Run Code Online (Sandbox Code Playgroud)
所以你看到我决定创建一本书,使我成为一个返回零数字的对象,如果失败则无异常,因此可以在没有太多垃圾代码的情况下保持最灵活的编程:
int abcInt = Libs.str.safeInt(abc);
Run Code Online (Sandbox Code Playgroud)
代码是:
public int safeInt(object ob)
{
if ((ob == null) || (String.IsNullOrEmpty(ob.ToString())))
return 0;
try
{
return Convert.ToInt32(
System.Text.RegularExpressions.Regex.Replace(ob.ToString(), @"@[^Ee0-9\.\,]+@i", "").
ToString(CultureInfo.InvariantCulture.NumberFormat)
);
}
catch (FormatException e)
{
return 0;
}
}
Run Code Online (Sandbox Code Playgroud)
但我想更进一步,做这样的事情:
int abcInt = (safeInt)abc;
Run Code Online (Sandbox Code Playgroud)
怎么做?
无法将'string'类型转换为'Libs.safeInt.safeInt'
我不明白,因为它给了我错误代码:
Socket socket = new Socket(
AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Udp
);
Run Code Online (Sandbox Code Playgroud)
返回错误:
me@machine:~/Demo/bin/Debug$ mono Demo.exe
Marshaling clicked signal
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Sockets.SocketException: Protocol not supported
at System.Net.Sockets.Socket..ctor (AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType) [0x00000] in <filename unknown>:0
...
at Gtk.Application.gtk_main()
at Gtk.Application.Run()
at Demo.MainClass.Main(System.String[] args)
Run Code Online (Sandbox Code Playgroud)
但我的系统支持UDP连接:
me@machine:~$ nc -u -v host.com 53
Connection to host.com 53 port [udp/domain] …Run Code Online (Sandbox Code Playgroud) 我需要将十六进制字符串值处理为浮动颜色。
真实颜色是(RGBA格式)
{ 0.63671875f, 0.76953125f, 0.22265625f, 1.0f }
Run Code Online (Sandbox Code Playgroud)
为绿色,0 相当于 00,1 相当于 FF。但需要将颜色转换为 0-255 小数,以计算 0 到 255 之间的百分比并设置浮点值。
如何通过示例转换#AABBCCFF为浮点数组?
当 parsecolor 我有整数值时:
Color.parseColor("#AABBCCFF");
Run Code Online (Sandbox Code Playgroud)
但是如何将整数转换为浮点数中的每种颜色呢?红绿蓝和阿尔帕
有一个对象列表并按每个对象调用一个函数,但是canot保留了上下文,例如:
std::list<Ob> objs;
Ob ob;
ob.settings(/*...*/);
objs.push_back(ob);
/*...*/
for (Ob obj : objs)
{
obj.increase();
}
Run Code Online (Sandbox Code Playgroud)
该increase()函数总结一个局部变量,例如:
class Ob
{
private:
int a = 0;
Run Code Online (Sandbox Code Playgroud)
而......
Ob::increase(){ this->a++; }
Run Code Online (Sandbox Code Playgroud)
但a只增加内循环,如果调用10次canot保持最后一个值.
如何保持对象的上下文?