Android 线性布局中的多视图线
如何识别设备屏幕上没有更多的空间,以便在下一行添加视图。 大概是这样的: 我得到了这个: 使用此xml:Android 线性布局中的多视图线,android,textview,android-linearlayout,Android,Textview,Android Linearlayout,如何识别设备屏幕上没有更多的空间,以便在下一行添加视图。 大概是这样的: 我得到了这个: 使用此xml: <LinearLayout android:orientation="horizontal" android:padding="5dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <Text
<LinearLayout
android:orientation="horizontal"
android:padding="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tournament_client"
android:textSize="@dimen/text_small_p"
android:textColor="@color/grey_line"
android:background="@color/black_10"
android:text="Lorem Ipsum"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tournament_client"
android:textSize="@dimen/text_small_p"
android:textColor="@color/grey_line"
android:background="@color/black_10"
android:text="Lorem Ipsum"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tournament_client"
android:textSize="@dimen/text_small_p"
android:textColor="@color/grey_line"
android:background="@color/black_10"
android:text="Lorem Ipsum"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tournament_client"
android:textSize="@dimen/text_small_p"
android:textColor="@color/grey_line"
android:background="@color/black_10"
android:text="Lorem Ipsum"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tournament_client"
android:textSize="@dimen/text_small_p"
android:textColor="@color/grey_line"
android:background="@color/black_10"
android:text="Lorem Ipsum"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tournament_client"
android:textSize="@dimen/text_small_p"
android:textColor="@color/grey_line"
android:background="@color/black_10"
android:text="Lorem Ipsum"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tournament_client"
android:textSize="@dimen/text_small_p"
android:textColor="@color/grey_line"
android:background="@color/black_10"
android:text="Lorem Ipsum"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tournament_client"
android:textSize="@dimen/text_small_p"
android:textColor="@color/grey_line"
android:background="@color/black_10"
android:text="Lorem Ipsum"
android:layout_margin="5dp"
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
正如Ertyguy所说,我使用FlowLayout解决了这个问题,它的工作原理类似于charm: 在XML中使用此选项:
<com.theapplabperu.hazfutbol.Utils.FlowLayout
android:id="@+id/layout_characteristics"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_marginBottom="10dp"
android:layout_width="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:layout_height="wrap_content">
如果您希望发生这种情况,您应该研究LinearLayout溢出或流布局,为什么不改用GridLayout呢?我应该如何使用GridLayout来实现该功能呢。
for (String caracteristics : myPlayer.getCaracteristics())
{
i = i+1;
TextView tv = new TextView(myContext);
tv.setText(caracteristics);
tv.setId(i + 20);
tv.setPadding(10, 10, 10, 10);
tv.setTextSize(14);
tv.setTextColor(myContext.getResources().getColor(R.color.gray_tags));
tv.setBackgroundDrawable(getDrawable(R.drawable.tags_shape));
FlowLayout.LayoutParams layoutParams = new FlowLayout.LayoutParams(30, 15);
tv.setLayoutParams(layoutParams);
lnrGameChars.addView(tv);
}