2015-11-06 44 views
2

請參見下圖: Multiple Tags appearing side by side顯示博客風格標籤側由多行(安卓)側

我想在一個Android應用程序,以顯示一組並排標籤的一面。 條件是:

  • 每個標籤都出現在前一個標籤的旁邊。
  • 如果水平空間用盡,則下一個標記將出現在新行中。
  • 如果標籤中有多個單詞並且標籤的某些單詞只有空格,請將整個標籤移動到一個新行中。但是,如果標籤已經在新行中,請讓標籤分成兩行。

我不確定這種技術被稱爲什麼。任何有關該問題的幫助,無論是通過代碼或鏈接到圖書館,將不勝感激。

回答

2

您可以使用簡單的庫標籤,FO例如:

AndroidTagGroup

添加到您的xml:

<me.gujun.android.taggroup.TagGroup 
    android:id="@+id/tag_group" 
    style="@style/TagGroup" /> 

並添加代碼:

TagGroup mTagGroup = (TagGroup) findViewById(R.id.tag_group); 
mTagGroup.setTags(new String[]{"Tag1", "Tag2", "Tag3"}); 

Anoter解決方案:

AutoLabelUI

添加到XML:

<com.dpizarro.autolabel.library.AutoLabelUI 
     android:id="@+id/label_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

,並加入到代碼:

AutoLabelUI mAutoLabel = (AutoLabelUI) view.findViewById(R.id.label_view); 

AutoLabelUISettings autoLabelUISettings = new AutoLabelUISettings.Builder() 
                   .withMaxLabels(5) 
                   .withIconCross(R.drawable.cross) 
                   .withBackgroundResource(android.R.color.holo_blue_bright) 
                   .withLabelsClickables(false) 
                   .withShowCross(true) 
                   .withTextColor(android.R.color.holo_red_dark) 
                   .withTextSize(R.dimen.label_title_size) 
                   .build(); 

mAutoLabel.setSettings(autoLabelUISettings); 

此外,您還可以使用HashtagView

+0

有沒有一種方法可以在AutoLabelUI中添加填充和標記間距。或者我可以從AndroidTagGroup刪除圓邊? – Umair

0

@Umair 你也可以做同樣的事情源自Xml:<com.dpizarro.autolabel.library.AutoLabelUI android:id="@+id/label_view" android:layout_width="wrap_content" android:layout_height="wrap_content" autolabel:icon_cross="@drawable/cross" autolabel:label_background_res="@color/light_greylabel" autolabel:label_clickable="true" autolabel:label_padding="5dp" autolabel:max_labels="10" autolabel:show_cross="true" autolabel:text_color="@color/app_grey" autolabel:text_size="@dimen/label_title_size" />

你可以從Here