我在这个应用程序中创建一个聊天应用程序我必须显示连接到登录用户的所有用户名,所以我在对话框中显示这些数据,实际上问题是相对布局中具有不同样式的不同文本视图并排自动排列,如果布局宽度占用3个文本视图,剩下的两个文本视图应该在第三行,就像那样。请帮助我
例如:
答案 0 :(得分:0)
试试这个:
<LinearLayout
android:id="@+id/categoriesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:background="@color/view_background"
android:orientation="vertical" >
<TextView
android:id="@+id/tagsTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="4dp"
android:text="@string/title"
android:textColor="@color/view_title"
android:textSize="18sp" />
<LinearLayout
android:id="@+id/tagsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:gravity="left"
android:orientation="vertical" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:orientation="horizontal"
android:padding="2dp" >
<Button
android:id="@+id/categoryIndications"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:background="@drawable/xml_category_count_bubble"
android:enabled="false"
android:minWidth="20dp"
android:padding="4dip"
android:textColor="#FFFFFF"
android:textSize="14sp"
android:textStyle="bold" />
<Button
android:id="@+id/categoryName"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:background="@drawable/xml_category_name_bubble"
android:enabled="false"
android:minWidth="40dp"
android:padding="4dip"
android:textColor="@color/view_text"
android:textSize="14sp" />
而且:
private void setTags(){
LinearLayout tagsContainer;
// Categories
tagsContainer = (LinearLayout) rootView.findViewById(R.id.tagsContainer);
// Container of the tags
tagsContainer.removeAllViews();
tagsContainer.refreshDrawableState();
// Indicate category layout
LinearLayout indicateLayout = (LinearLayout)
LayoutInflater.from(getActivity().getApplicationContext()).
inflate(R.layout.message_indicate_category, null);
if(YOUR_TEXTVIEW_STRINGS_ARRAY.size()>0){
Button textButton;
LinearLayout tag;
for(int i = 0; i<YOUR_TEXTVIEW_STRINGS_ARRAY.size();i++){
// View of the tag
tag = (LinearLayout)
LayoutInflater.from(getActivity().getApplicationContext()).
inflate(R.layout.customview_tag, null);
textButton= (Button)tag.findViewById(R.id.categoryName);
textButton.setText(YOUR_TEXTVIEW_STRINGS_ARRAY..get(i));
textButton = (Button)tag.findViewById(R.id.categoryIndications);
textButton.setText(YOUR_TEXTVIEW_STRINGS_ARRAY.get(i));
tagsContainer.addView(tag);
}
}
else{
// View of the tag
indicateLayout = (LinearLayout)
LayoutInflater.from(getActivity().getApplicationContext()).
inflate(R.layout.message_indicate_category, null);
tagsContainer.addView(indicateLayout);
}
}