我有N个长宽比为Aitem(X:Y)的矩形项目。
我有一个长宽比为Aview的矩形显示区域
这些项目应以表格形式布置(即r行,c列)。
什么是理想的网格行x列,以使单个项目最大?(当然,行*列> = N-即可能有“未使用的”网格位置)。
一个简单的算法可以遍历行= 1..N,计算所需的列数,并使行/列对具有最大的项。
我想知道是否有一个非迭代算法(例如,对于Aitem = Aview = 1,行/列可以由sqrt(N)近似)。
GWT树看起来大致如下:
<div class="gwt-Tree">
<div style="padding-top: 3px; padding-right: 3px;
padding-bottom: 3px; margin-left: 0px;
padding-left: 23px;">
<div style="display:inline;" class="gwt-TreeItem">
<table>
...
</table>
</div>
</div>
<div ...>
</div>
...
</div>
Run Code Online (Sandbox Code Playgroud)
我的问题是:我应该如何更改单个树行的填充?我想我可以按照设置CSS规则的方式做一些事情,.gwt-Tree > div但这看起来很糟糕.有更优雅的方式吗?
解决方案:显然没有更优雅的方式.以下是我们所做的,FWIW:
.gwt-Tree > div:first-child {
width: 0px !important;
height: 0px !important;
margin: 0px !important;
padding: 0px !important;
}
.gwt-Tree > div {
padding: 0px 5px !important;
}
.gwt-Tree > div[hidefocus=true] {
width: 0px !important;
height: 0px !important;
margin: 0px !important;
padding: 0px !important;
}
Run Code Online (Sandbox Code Playgroud) (对于SwiftUI,不是普通的UIKit)非常简单的示例代码,例如,在灰色背景上显示红色框:
struct ContentView : View {
@State var points:[CGPoint] = [CGPoint(x:0,y:0), CGPoint(x:50,y:50)]
var body: some View {
return ZStack {
Color.gray
.tapAction {
// TODO: add an entry to self.points of the location of the tap
}
ForEach(self.points.identified(by: \.debugDescription)) {
point in
Color.red
.frame(width:50, height:50, alignment: .center)
.offset(CGSize(width: point.x, height: point.y))
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我假设不是需要tapAction,而是需要TapGesture或其他东西?但即使在那儿,我也看不到任何方法来获取有关水龙头位置的信息。我将如何处理?
要么我不理解方法getActualMaximum(int)或字段WEEK_OF_YEAR,要么涉及到Sun漏洞(或全部三个)......有人可以向我解释为什么(至少在德语区域设置中 ......)以下代码:
Locale.setDefault( Locale.GERMAN );
Calendar c = Calendar.getInstance();
c.set( Calendar.YEAR, 2010 );
c.set( Calendar.MONTH, 0 );
c.set( Calendar.DAY_OF_MONTH, 1 );
System.out.println("max: "+c.getActualMaximum( Calendar.WEEK_OF_YEAR ));
System.out.println("actual: "+c.get( Calendar.WEEK_OF_YEAR ));
Run Code Online (Sandbox Code Playgroud)
产生以下输出:
max: 52
actual: 53
Run Code Online (Sandbox Code Playgroud)
这是Javadoc getActualMaximum(int):
给定此Calendar的时间值,返回指定日历字段可能具有的最大值.例如,MONTH字段的实际最大值在某些年份为12,在希伯来日历系统中为其他年份的13.
编辑
情节变粗.在英语语言环境(-Duser.language=en -Duser.country=us)中,输出为:
max: 52
actual: 1
Run Code Online (Sandbox Code Playgroud)
似乎指出它是德国语言环境的Sun bug?
我有一个连接到平移手势识别器的 UITextView。当我将手指拖到文本视图上时,我使用 characterIndexForPoint 方法来确定我的手指在哪个字符上,然后在该点突出显示文本。
在视图中的文本有换行符的某些情况下,即使我传入相同的参数,此方法似乎返回不同的结果。touch 方法被连续调用两次,一次 charIndex 是 167,然后是 270。
我检查了文本视图的 AttributedString 并且在两种情况下它的字体大小相同。
- (IBAction)touched:(UIPanGestureRecognizer *)sender {
if (self.txtView.isFirstResponder) {
return;
}
if (sender.state == UIGestureRecognizerStateChanged) {
CGPoint touchPoint = [sender locationInView:self.txtView];
NSUInteger charIndex = [self.txtView.layoutManager
characterIndexForPoint:touchPoint
inTextContainer:self.txtView.textContainer
fractionOfDistanceBetweenInsertionPoints:0];
...
Run Code Online (Sandbox Code Playgroud)
这是一个已知的错误?难道我做错了什么?
在我的Java程序中,我想确定系统上安装了哪个.NET Framework.这样做的最好(也是最简单)方法是什么?
回答谢谢scubabbl!它用于检查目录中System.getenv( "WINDIR" ) + "\\Microsoft.NET\\Framework"以字母"v"开头的目录.
我有以下代码:
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
public class ScratchPad {
public static void main(String args[]) throws Exception {
String html ="<html>"+
"<head>"+
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"/>"+ // this is the problem right here
"<title>Error 400 BAD_REQUEST</title>"+
"</head>"+
"<body>"+
"<h2>HTTP ERROR: 400</h2><pre>BAD_REQUEST</pre>"+
"<p>RequestURI=null</p>"+
"<p><i><small><a href=\"http://jetty.mortbay.org\">Powered by jetty://</a></small></i></p>"+
"</body>"+
"</html>";
JFrame f = new JFrame();
JEditorPane editor = new JEditorPane();
editor.setEditable( false );
editor.getDocument().putProperty( "Ignore-Charset", "true" ); // this line makes no difference either way
editor.setContentType( "text/html" );
editor.setText( …Run Code Online (Sandbox Code Playgroud) Double out = otherTypes.someMethod(c, c2);
assertEquals((Double)-1.0D, out);
Run Code Online (Sandbox Code Playgroud)
我得到错误"Double无法解析"(assertEquals中的Double),除了提取变量之外,还有什么方法可以解决它吗?
这是Java中的错误还是非常有用的功能,无法修复?
我有一个带有junit目标的Ant脚本,我希望它使用与basedir不同的工作目录启动VM.我该怎么做?
这是我的目标的伪版本.
<target name="buildWithClassFiles">
<mkdir dir="${basedir}/UnitTest/junit-reports"/>
<junit fork="true" printsummary="yes">
<classpath>
<pathelement location="${basedir}/UnitTest/bin"/>
<path refid="classpath.compile.tests.nojars"/>
</classpath>
<jvmarg value="-javaagent:${lib}/jmockit/jmockit.jar=coverage=:html"/>
<formatter type="xml" />
<test name="GlobalTests" todir="${basedir}/UnitTest/junit-reports" />
</junit>
</target>
Run Code Online (Sandbox Code Playgroud) java ×7
.net-3.5 ×1
algorithm ×1
ant ×1
calendar ×1
cocoa-touch ×1
css ×1
gwt ×1
html ×1
jeditorpane ×1
junit ×1
layout ×1
localization ×1
math ×1
objective-c ×1
selenium ×1
swift ×1
swiftui ×1
swing ×1
syntax ×1
textkit ×1
tree ×1
week-number ×1