如何在Android中创建布局以水平列出文本视图

如何在Android中创建布局以水平列出文本视图,android,android-layout,android-linearlayout,Android,Android Layout,Android Linearlayout,我想创建如下布局: Name1、Something1、OtherThing和Name2是文本视图(它们中的每一个都可以通过不同的操作单击),通过编程方式添加到父布局中。有时,有太多的元素,以适应一行。我应该使用哪种布局作为父级,使文本视图水平放置,但可能会“断线”?水平线性布局不起作用。请尝试以下操作: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.andr

我想创建如下布局:

Name1、Something1、OtherThing和Name2是文本视图(它们中的每一个都可以通过不同的操作单击),通过编程方式添加到父布局中。有时,有太多的元素,以适应一行。我应该使用哪种布局作为父级,使文本视图水平放置,但可能会“断线”?水平线性布局不起作用。

请尝试以下操作:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="STUFF"
    android:textSize="30dp"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Something1" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="OtherThing" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name2" />

</LinearLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="MORE STUFF"
    android:textSize="30dp"/>

</LinearLayout>

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="match_parent"
   android:layout_height="match_parent">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="STUFF"
    android:textSize="30dp"/>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Something1" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="OtherThing" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name2" />

</LinearLayout>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="MORE STUFF"
    android:textSize="30dp"/>

</LinearLayout>

尝试使用:

FlowLayout是一种在多行中显示其子级的布局 取决于它们的大小。


尝试使用:

FlowLayout是一种在多行中显示其子级的布局 取决于它们的大小。



请展示您的Java代码。使用分隔线是什么意思?请展示您的Java代码。使用分隔线是什么意思?太棒了:)非常感谢。您知道如何在内部视图中添加边距吗?我试过这样做,但不起作用:FlowLayout.MarginLayoutParams params=新建FlowLayout.MarginLayoutParams(FlowLayout.LayoutParams.WRAP_内容,FlowLayout.LayoutParams.WRAP_内容);参数设置边距(10,0,0,0);addView(myInnerView,参数);不,我想在每个内部视图中添加marginLeft。myInnerView是我添加到FlowLayout.FlowLayout.LayoutParams params=新的FlowLayout.LayoutParams(FlowLayout.LayoutParams.WRAP_内容,FlowLayout.LayoutParams.WRAP_内容)的文本视图之一;参数设置边距(5,0,0,0);myInnerView.setLayoutParams(params);myFlowLayout.addView(myInnerView);让我们来。太棒了:)非常感谢。你知道如何给内部视图添加边距吗?我试过这样做,但不起作用:FlowLayout.MarginLayoutParams params=新建FlowLayout.MarginLayoutParams(FlowLayout.LayoutParams.WRAP_内容,FlowLayout.LayoutParams.WRAP_内容);参数设置边距(10,0,0,0);addView(myInnerView,参数);不,我想在每个内部视图中添加marginLeft。myInnerView是我添加到FlowLayout.FlowLayout.LayoutParams params=新的FlowLayout.LayoutParams(FlowLayout.LayoutParams.WRAP_内容,FlowLayout.LayoutParams.WRAP_内容)的文本视图之一;参数设置边距(5,0,0,0);myInnerView.setLayoutParams(params);myFlowLayout.addView(myInnerView);让我们一起来。@Fabio Venturi Pastor是伟大的解决方案。@Fabio Venturi Pastor是伟大的解决方案。