我的申请有问题.我最近添加了ScrollView作为LinearLayout的Parent.将设备方向翻转为横向时,我的按钮会在顶部被切断.当我向下滚动时,我可以看到最后一个按钮就好了,在它的末尾有额外的"黑色空间",只有顶部被切掉了.我环顾四周,我不确定为什么会这样.这是一些图片,所以你可以理解它的外观.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:gravity="center_vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center">
<Button
android:id="@+id/BeefButton"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/beefbutton"
android:text="Beef"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"/>
<Button
android:id="@+id/PoultryButton"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="match_parent"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/chickenbutton"
android:text="Poultry"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"/>
<Button
android:id="@+id/FishButton"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/fishbutton"
android:text="Fish"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"
android:layout_gravity="center"
android:layout_width="match_parent"/>
<Button
android:id="@+id/PorkButton"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/porkbutton"
android:text="Pork"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"
android:layout_gravity="center"
android:layout_width="match_parent"/>
<Button
android:id="@+id/VegetablesButton"
android:layout_height="wrap_content"
android:background="@drawable/backgroundlayer"
android:drawableLeft="@drawable/vegetablesbutton"
android:text="Vegetables"
android:textColor="#FFFFFF"
android:textSize="32px"
android:textColorHighlight="#FF6600"
android:layout_gravity="center"
android:layout_width="match_parent"/>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud) 我正在使用EhCache的装饰器SelfPopulatingCache
,当缓存尝试加载新条目时出现问题,但它不存在(即它在数据库中不存在).因此缓存会将一个null
值放入缓存中,以取消阻止密钥上的任何其他获取,但是下一个线程将执行相同的数据库调用,因为它从缓存中收到"null".这意味着它认为需要加载条目 - 即使实际上它是空的,因为数据不存在于任何地方.我觉得我做错了什么.
(伪代码)
Value v = cache.get(key); // multiple threads will block here
if (v == null)
cache.put(key, getValueFromDB()); // this might put a null value
Run Code Online (Sandbox Code Playgroud)
我目前的解决方案是不放空,而是放置占位符Object
并检查它.
Value v = cache.get(key);
if (v == null)
cache.put(key, getValueFromDB());
else if (v == NOENTRYOBJECT)
return null;
else
return v;
Run Code Online (Sandbox Code Playgroud)
思考?
我正在寻找一个基本库来提供我可以嵌入Java应用程序的JMX MBean的HTML视图.这听起来像Sun的com.sun.jdmk.comm.HtmlAdaptorServer符合账单(此处引用).但是,该工具似乎在某种程度上受到许可......
我所需要的基本Web UI就像参考文章一样:http: //java.sun.com/developer/technicalArticles/J2SE/fig6.gif
我正在运行一个servlet容器(Jetty),因此这个库可以部署为WAR.但我不在乎它是否只是打开自己的插座.
我看过jManage,但它似乎不是为嵌入式使用而设计的.
有什么建议?
我是Scala编程的新手,在函数式编程和不可变集合方面遇到了一些困难.我试图将我的数字代码从C++移植到Scala.
很多时候我有代码在小向量上运行,如下所示:
double ytmp[6];
for (int i=0; i<6; i++) {
ytmp[i] = y[i] + h*(a41*dydx[i] + a42*k2[i] + a43*k3[i]);
}
Run Code Online (Sandbox Code Playgroud)
如何在高效的Scala中编写类似的东西?我考虑过在开始时使用简单列表,但是对于不可变类型有问题,所以我不能只创建一个空列表ytmp并稍后修改它,就像我习惯于使用C++一样.谢谢您的帮助
技术: - Java 1.5或1.6 - Hibernate 3.4
为了避免在更改列名或表名时更改多个位置上的列名,我希望有一个常量文件.
我有以下疑问?
一种可能的解决方案是维护一个全局文件,该文件存储数据库中所有表的列名的常量.喜欢
class DbConstants
{
public static final String EMPLOYEE__PERFORMANCE_DESC="performance_desc";
}
Run Code Online (Sandbox Code Playgroud)在上面的情况中,employees是表的名称,performance_desc是列名的名称.因此,如果两个表都有列名,则遵循一种tablename__columnname格式来命名一个常量,以避免两个不同表的两个常量之间发生冲突.
我看到这种方法的一个问题是,随着数据库的增长,该文件中没有任何常量将增长到数千个,这很难管理.其他问题是如果更改了表名,我必须更改所有表的前缀表名.
假设我将上面示例中的列名称从performance_desc更改为achievement_desc.在这种情况下,我很可能也想改变常数,即从EMPLOYEE__PERFORMANCE_DESC到EMPLOYEE__ACHIEVEMENT_DESC.因为在这种情况下我需要更改列名和常量名称我没有看到在我的代码中直接使用常量而不是列名的用处尽管有一个好处,在更改常量名称时我可以使用折射来反映常量名称名称在引用的地方更改.似乎要么没有太多使用常量,要么我错误地使用它.
在项目代码中,我似乎有人为每个表列列表定义一个类来定义常量,如下所示.
public class tbl_Employee
{
public static final PERFORMANCE_DESC=performance_desc;
}
Run Code Online (Sandbox Code Playgroud)这可以解决一些与全局文件一样的问题,比如表名更改只会导致类名更改.这个问题的一个主要问题是我使用类仅用于定义不是良好编码实践的常量.
阅读一些有关值字符串Enum的内容而不是int不确定它是否可用于java 1.5或1.6以及是否建议在给定方案中使用它.
定义db常量的最佳做法是什么?
使用db常量真的很有用吗?
如果我像上面提到的那样为每个表使用一个类,我面临的一个问题是命名约定.表的名称和对应的类名称之间应该有什么关系,它们定义表的列的常量.
以上案例仅涵盖列名而非表名的情况.我可能想在代码中使用常量而不是表名,因此应该为表名定义常量.
经常有人认为,一旦产品或相关版本发布,表名和列名就不会发生太大变化.表名和列名的更改主要发生在开发阶段或功能增强(新版本)期间.避免对表名或列名使用常量是否是强有力的论据?
请建议我如何才能使我的问题更具代表性,或者我错过了哪些问题未被投票?
当我阅读 http://msdn.microsoft.com/en-us/library/ms165394.aspx时:
对于VB:
在Snippet元素内,添加References元素和插入代码段时添加对项目的引用的所有必需子元素.
对于C#
Visual C#代码片段不支持References部分,因此必须手动将对System.Windows.Forms.dll的引用添加到项目中
什么根本原因阻止C#支持像VB这样的引用?
更新:我看到这个发布http://visualstudiogallery.msdn.microsoft.com/en-us/dc06b54c-b6c4-4cf5-8203-a09c6979e881
但它甚至不像Code Snippet References那样功能齐全,因为Code Snippet References允许您一次添加多个引用,而不是一个一个.
据说C#比VB.NET更"专业",人们会期望C#更具特色而不是更有限,或者"专业"意味着你必须像"手工"那样艰难地做到这一点:p
C#团队什么时候能赶上VB.NET团队?
我如何用Qt播放声音?我试过这个:
QSound::play("sounds/croack.wav");
Run Code Online (Sandbox Code Playgroud)
QSound在我的ubuntu上不起作用(似乎它需要NAS,虽然在我安装之后它仍然无效).有一个简单的单行Qt解决方案还是我需要投入SDL或其他东西?
Xcode 3.2.5,iOS 4.2(模拟器),Cocos2D 0.99.5
在本教程之后会出现一个精彩的崩溃,如下所示.
我没有通过谷歌在任何网站上找到一个(直接)相关的东西.我得到的最接近的是这个网站上的其他东西有相同的错误,但完全不同的原因.(无论如何,我假设如此.但是,鉴于0.99.5带有两个Analyzer结果,它可能只是一个糟糕的版本...)
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSInvocation invocationWithMethodSignature:]: method signature argument cannot be nil'
*** Call stack at first throw:
(
0 CoreFoundation 0x013cbbe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x015205c2 objc_exception_throw + 47
2 CoreFoundation 0x0133bb09 +[NSInvocation invocationWithMethodSignature:] + 553
3 FirstGame 0x0005ddd4 -[CCMenuItem initWithTarget:selector:] + 308
4 FirstGame 0x0005e528 -[CCMenuItemLabel initWithLabel:target:selector:] + 104
5 FirstGame 0x0005fb1d -[CCMenuItemFont initFromString:target:selector:] + 365
6 FirstGame 0x0005f8db +[CCMenuItemFont itemFromString:target:selector:] + 123
7 …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个脚本(show_volume.sh),可以在短时间内多次调用.我需要一种方法来确定是否只有一个运行此脚本的实例.我想我可以使用ps
,所以我在Bash中编写了这个函数:
is_only_process(){
PCOUNT=`ps -a | grep show_volume.sh | wc -l`
echo $PCOUNT
if (( PCOUNT==1 )); then
return 1
fi
return 0
}
Run Code Online (Sandbox Code Playgroud)
所以我添加了这两行
is_only_process
sleep 4
Run Code Online (Sandbox Code Playgroud)
并启动了这个脚本一次,但输出echo $PCOUNT
对我没有任何意义.我总是按预期得到值2而不是1.当我运行此命令
ps -a | grep show_volume.sh | wc -l
在脚本运行时从另一个终端,我收到值1.当我连续多次运行此脚本时,几乎相同,例如使用for循环运行10次.当我在使用另一个终端时收到正确的值时,脚本本身会确定太高的值.
现在,为什么这个脚本会确定这些奇怪的值?
我有一个带有以下签名的方法:
public Guid FindTermIDFromCustomProperty()
{
// Logic here to find an item and return the guid
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果在函数中没有找到任何项目,那么将不会返回GUID - 这不用说了!但有没有办法返回一些平淡的GUID?
更好的是,我可以采用更通用的方法,不仅仅是针对GUID,而且通常在我返回强类型时?我真的不想将对象用作返回类型,必须有更好的方法.
提前致谢.