我正在製作一款應用程序,允許用戶以圖形方式從遊戲創建自定義商店,但由於我想添加一個標籤來顯示多少圖標項目在商店中,但由於imageview已經在Tile窗格上,它會在旁邊創建一個標籤,但我想在它上面創建一個標籤。在TilePane上的圖像視圖頂部添加標籤
1
A
回答
0
您可以製作標籤並將圖像作爲圖形節點應用於標籤。當選擇這些項目時,您可以調用標籤上的label.setText("text string")
以根據需要更改標籤的文本或CSS樣式。如果項目需要互動,您可能需要製作按鈕而不是標籤。
下面的方法通過使用contentDisplay="TOP" graphicTextGap="-40.0"
和-fx-padding: 0 0 20 0;
的組合來定位文本有點詭計,這有點違反直覺。
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<StackPane id="StackPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="-1.0" prefWidth="-1.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
<children>
<TilePane hgap="10.0" prefColumns="3" prefHeight="-1.0" prefRows="1" prefWidth="-1.0" style="-fx-background-color: linear-gradient(palegreen, forestgreen); -fx-padding: 20px;" vgap="10.0">
<children>
<Label contentDisplay="TOP" graphicTextGap="-40.0" style="-fx-font-size: 20px; -fx-text-fill: gold; -fx-padding: 0 0 20 0;" text="Roast Beef">
<graphic>
<ImageView fitHeight="0.0" fitWidth="0.0" mouseTransparent="true" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="http://icons.iconarchive.com/icons/rockettheme/ecommerce/256/piggy-bank-icon.png" backgroundLoading="true" />
</image>
</ImageView>
</graphic>
</Label>
<Label contentDisplay="TOP" graphicTextGap="-40.0" style="-fx-font-size: 20px; -fx-text-fill: gold; -fx-padding: 0 0 20 0; -fx-border-color: palegoldenrod; -fx-border-width: 5px; -fx-border-radius: 10px; -fx-border-insets: -5px; " text="Bag 'o' Love">
<graphic>
<ImageView fitHeight="0.0" fitWidth="0.0" mouseTransparent="true" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="http://icons.iconarchive.com/icons/rockettheme/ecommerce/256/bag-icon.png" backgroundLoading="false" />
</image>
</ImageView>
</graphic>
</Label>
<Label contentDisplay="TOP" graphicTextGap="-40.0" style="-fx-font-size: 20px; -fx-text-fill: gold; -fx-padding: 0 0 20 0;" text="Show Me">
<graphic>
<ImageView fitHeight="0.0" fitWidth="0.0" mouseTransparent="true" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="http://icons.iconarchive.com/icons/rockettheme/ecommerce/256/wallet-icon.png" backgroundLoading="true" />
</image>
</ImageView>
</graphic>
</Label>
</children>
</TilePane>
</children>
</StackPane>
<!-- icon usage license:
Creative Commons with attribution,
back link to http://www.rockettheme.com required -->
這也許不是達到你想要什麼,你可以創建一個從地區派生的自定義組件ShopItem最好的方式。使用自定義組件,您可以提供佈局邏輯,以在內部將文本(以及其他圖形根據需要)層疊到項目圖像的頂部。這種佈局邏輯應該比上面提供的機制更直觀。
另一種方法是將每個商店項目製作爲包含圖像和文本標籤的AnchorPane。
自定義組件方法雖然更加靈活,但有點複雜,所以我只是在這裏提供了基於標籤的簡單解決方案。
相關問題
- 1. 如何在Xamarin.Forms中的標籤視圖頂部顯示圖像?
- 2. UIView標籤欄頂部,就像iPhone上的HTML視圖
- 3. 如何在現有視圖頂部疊加圖標圖像
- 4. 如何在現有視圖頂部疊加圖標圖像
- 5. 在運行時在圖像視圖頂部添加按鈕
- 6. 在列表視圖頂部添加「正在載入」圖像
- 7. 追加圖像頂部的圖標
- 8. python中的圖像頂部的標籤
- 9. 圖像頂部的位置標籤
- 10. 如何在UINavigation欄頂部添加橫幅/圖像視圖
- 11. 上的按鈕,其是在滾動視圖的頂部添加圖像
- 12. 如何在我的圖像視圖頂部添加裝飾圖像
- 13. 如何在UIPopoverController頂部添加視圖
- 14. 在UIScrollView頂部添加視圖
- 15. 使用Xcode4.2添加在視圖上的頂部圖像,需要援助
- 16. 添加標籤視圖android
- 17. 在android中,如何將標籤放在包含頂部圖像的視圖中?
- 18. 添加空格到圖像的頂部
- 19. 在現有視圖頂部添加新視圖
- 20. 如何在視圖頂部添加模糊視圖?
- 21. 滾動視圖在彼此頂部添加視圖
- 22. 添加視圖底部的地圖片段內的標籤
- 23. 將子視圖添加到iOS的滾動視圖的頂部
- 24. 如何在列表視圖的頂部添加添加數據
- 25. Obj-C,頂部居中視圖上的標籤/
- 26. 覆蓋gridview頂部的圖像視圖
- 27. 在註釋標註頂部添加子視圖
- 28. 在按鈕上添加圖像圖標?
- 29. jquery/javascript如何在列標題頂部添加圖像
- 30. Php替換圖像標記在頂部添加html
謝謝!我使用了從Region創建自定義組件的方法。 – TopRS