嗨我想要旋转文字(-40)/我有问题,当文字很短这个开始不同的时候我希望那个文字开始时我标记。这个朋友我喜欢这个
for(int i =0 ;i<Config.busSizeInView;i++){
nameBusStop.add(new Text("Konstytucji 3 Maja - Dworzec PKS 02"));
}
for(int i=0 ; i<nameBusStop.size(); i++){
nameBusStop.get(i).setRotate(-40);
nameBusStop.get(i).setText(Main3.listBusStops.get(i).getName());
}
for(int i =0 ; i<nameBusStop.size(); i++){
nameBusStop.get(i).relocate(i*Config.xSize/Config.busSizeInView-Config.padding-10, Config.ySize - Config.ySize/6 - Config.padding*3);
}
line.getChildren().addAll(canvas,txtPane);
Pane txtPane = new Pane();
for(Text text : nameBusStop){
text.setFont(Font.font ("Verdana", 20));
txtPane.getChildren().add(text);
}
line.getChildren().addAll(canvas,txtPane);
- (void) viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.tintColor = [UIColor redColor]
}
文字较长时 {{3}}
答案 0 :(得分:1)
您也可以使用Canvas
绘制字符串:
public static void drawStop(double x, double y, String text, GraphicsContext gc) {
gc.save();
gc.translate(x, y);
gc.fillRect(-5, 0, 10, 10);
gc.rotate(-40);
gc.fillText(text, 5, 0);
gc.restore();
}
@Override
public void start(Stage primaryStage) {
Canvas canvas = new Canvas(900, 400);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setFont(Font.font ("Verdana", 20));
drawStop(100, 380, "Stop 1", gc);
drawStop(200, 380, "Stop 2", gc);
drawStop(500, 380, "Stop 3 Stop 3 Stop 3 Stop 3 Stop 3 Stop 3", gc);
Scene scene = new Scene(new Group(canvas));
primaryStage.setScene(scene);
primaryStage.show();
}
或者,不要使用以儿童为中心的StackPane
。也不要使用rotate
属性,因为它围绕Node
的中心旋转。请使用Rotate
转换来围绕(0, 0)
旋转:
public static void drawStop(double x, double y, String text, GraphicsContext gc, Pane pane) {
gc.fillRect(x-5, y, 10, 10);
Text textNode = new Text(text);
textNode.setFont(Font.font ("Verdana", 20));
textNode.setBoundsType(TextBoundsType.VISUAL);
textNode.relocate(x, y-15);
textNode.getTransforms().add(new Rotate(-40));
pane.getChildren().add(textNode);
}
@Override
public void start(Stage primaryStage) {
Pane pane = new Pane();
Canvas canvas = new Canvas(900, 400);
pane.getChildren().add(canvas);
GraphicsContext gc = canvas.getGraphicsContext2D();
drawStop(100, 380, "Stop 1", gc, pane);
drawStop(200, 380, "Stop 2", gc, pane);
drawStop(500, 380, "Stop 3 Stop 3 Stop 3 Stop 3 Stop 3 Stop 3", gc, pane);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
}