Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 相对于彼此对齐文本视图_Android_Android Layout_Textview - Fatal编程技术网

Android 相对于彼此对齐文本视图

Android 相对于彼此对齐文本视图,android,android-layout,textview,Android,Android Layout,Textview,我有两个文本视图。 第一个文本视图包含动态文本,可以是小文本,也可以是大文本。 第二个文本视图包含静态小文本。 第二个文本视图应位于第一个文本视图的右侧 这就是它的工作原理: 当第一个文本较大时: 当文本较小时: 我如何制作这个布局?当第一个文本视图包含大文本时,使用相对或线性布局-第二个文本从屏幕上消失。您可以添加一个方向为“水平”的线性布局,并在其中添加两个文本视图 <LinearLayout ... android:orientation="horizon

我有两个文本视图。 第一个文本视图包含动态文本,可以是小文本,也可以是大文本。 第二个文本视图包含静态小文本。 第二个文本视图应位于第一个文本视图的右侧

这就是它的工作原理:

  • 当第一个文本较大时:
  • 当文本较小时:

我如何制作这个布局?当第一个文本视图包含大文本时,使用相对或线性布局-第二个文本从屏幕上消失。

您可以添加一个方向为“水平”的线性布局,并在其中添加两个文本视图

<LinearLayout
     ...
     android:orientation="horizontal">
   <TextView .../>
   <TextView .../>
</LinearLayout>

您可以添加方向为“水平”的线性布局,并在其中添加两个文本视图

<LinearLayout
     ...
     android:orientation="horizontal">
   <TextView .../>
   <TextView .../>
</LinearLayout>

试试这段代码,我想它会按照您的意愿工作

 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">

<TextView
    android:id="@+id/txt_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="asdasdadasdasdasdasdasdasdasdasdasdasdasdasd"/>

<TextView
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:text="2asdasdadasdasdasdasdasdasdasdasdasdasdasdasd"
    android:layout_height="wrap_content"/>

</LinearLayout>

试试这段代码,我想它会按照您的意愿工作

 <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">

<TextView
    android:id="@+id/txt_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="asdasdadasdasdasdasdasdasdasdasdasdasdasdasd"/>

<TextView
    android:layout_weight="1"
    android:layout_width="wrap_content"
    android:text="2asdasdadasdasdasdasdasdasdasdasdasdasdasdasd"
    android:layout_height="wrap_content"/>

</LinearLayout>

试试这个

将以下依赖项添加到build.gradle文件:

dependencies {
    compile 'com.google.android:flexbox:0.3.2'
}
用法

 <com.google.android.flexbox.FlexboxLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:flexWrap="nowrap"
        app:alignItems="stretch"
        app:alignContent="stretch" >

        <TextView
            android:id="@+id/textview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#ff0"
            android:text="niledfdfdfhfgfdgdfgdfgfgfggdfgdfggggggggggggggggggggggggggggggggggggggggggggggfhssdsdsdsfgdfgfgfgfgfggfgdgdfgfgfgdsddjfhdkjfhjshdf"            />

        <TextView
            android:id="@+id/textview2"
            android:layout_width="wrap_content"
            android:text="nilxcvxceshdfhd"
            android:background="@color/colorAccent"
            android:layout_height="wrap_content"
            app:layout_minWidth="50dp"
            app:layout_minHeight="20dp"
            app:layout_alignSelf="center"

            />

    </com.google.android.flexbox.FlexboxLayout>

输出

输出大文本

试试这个

将以下依赖项添加到build.gradle文件:

dependencies {
    compile 'com.google.android:flexbox:0.3.2'
}
用法

 <com.google.android.flexbox.FlexboxLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:flexWrap="nowrap"
        app:alignItems="stretch"
        app:alignContent="stretch" >

        <TextView
            android:id="@+id/textview1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#ff0"
            android:text="niledfdfdfhfgfdgdfgdfgfgfggdfgdfggggggggggggggggggggggggggggggggggggggggggggggfhssdsdsdsfgdfgfgfgfgfggfgdgdfgfgfgdsddjfhdkjfhjshdf"            />

        <TextView
            android:id="@+id/textview2"
            android:layout_width="wrap_content"
            android:text="nilxcvxceshdfhd"
            android:background="@color/colorAccent"
            android:layout_height="wrap_content"
            app:layout_minWidth="50dp"
            app:layout_minHeight="20dp"
            app:layout_alignSelf="center"

            />

    </com.google.android.flexbox.FlexboxLayout>

输出


大文本输出

显示您的代码所做的。xml和java文件。显示您的代码所做的。xml和java文件。