2015-11-06 48 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