2014-12-04 53 views
3

我正在用libgdx開發一個小遊戲,並在我的屏幕上我想要一個標籤(包裹在一個表格中),其中會有一個可點擊的文本鏈接(帶下劃線或與不同的顏色)是這樣的:LIBGDX:添加一個可點擊的文本鏈接

,您可以查看這裏的代碼

here

編輯:

我已經試過是:

HorizontalGroup monGroup = new HorizontalGroup(); 
Label howRotationRep = new Label("They have been based on the information provided on this ", new Label.LabelStyle(game.petiteFont, Color.WHITE)); 
howRotationRep.setWrap(true); 
howRotationRep.setWidth(tailleCell); 

Label test = new Label(" site", new Label.LabelStyle(game.petiteFont, Color.RED)); 
test.addListener(new ClickListener(){ 
@Override 
public void clicked(InputEvent event, float x, float y) { 

    Gdx.net.openURI("http://tetrisconcept.net/wiki/SRS"); 

} 
}); 
monGroup.addActor(howRotationRep); 
monGroup.addActor(test); 
table.add(monGroup).left().width(tailleCell); 

,這讓我這個

this

回答

0

您可以通過使用兩種不同的scene2d標籤爲「你可以查看代碼」和「這裏」,並設置點擊收聽到第二個做到這一點。你可以簡單地改變「這裏」標籤的顏色和位置是根據第一標籤位置就像使用以下pseduo代碼:

label2.x = label1.x + label1.getTextWidth(); 
label2.y = label1.y; 
5

如果您只需要標籤可點擊的一部分,我認爲最好的方式來實現這是一種有兩個標籤,這應該工作:

Label lblReviewCode = new Label("You can review the code ", skin); 
    Label lblReviewCodeLink = new Label("here", skin, "linkstyle"); 
    // If you don't want to provide a custom style... 
    //Label lblReviewCodeLink = new Label("here", skin); 
    lblReviewCodeLink.addListener(new ClickListener(){ 
     @Override 
     public void clicked(InputEvent event, float x, float y) { 
      Gdx.net.openURI("https://bitbucket.org/batman3000/batris"); 
     } 
    }); 
    // If you didn't provided the style, you can at least paint it blue by doing this... 
    //lblReviewCodeLink.setColor(Color.BLUE); 

    HorizontalGroup codeLink = new HorizontalGroup(); 
    codeLink.addActor(lblReviewCode); 
    codeLink.addActor(lblReviewCodeLink); 

    table.add(codeLink); 
+0

謝謝您的回答,但我已經嘗試過這一點,如果添加兩個標籤寬度超過了表格的寬度,這是這裏的情況下,它不能正常工作。此外,標籤必須進行包裝,以便可以在多行上顯示,因爲我有很長的句子要寫,而不僅僅是「你可以在這裏查看代碼」。除了即使標籤足夠短,當我將它們添加到水平組時,它們也是彼此重疊(疊加)(抱歉我的英文不好)。我不知道該怎麼辦? – 2014-12-05 12:16:29