相对于彼此对齐 TextView

2024-04-11

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

它应该是这样工作的:

  • when first text is big: enter image description here
  • and when text is small: enter image description here

我怎样才能做出这个布局?使用相对或线性布局,当第一个 TextView 包含大文本时,第二个文本就会从屏幕上消失。


尝试这个FlexboxLayout https://github.com/google/flexbox-layout

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

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

Usage

 <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>

OUTPUT enter image description here

OUTPUT WITH BIG TEXT enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

相对于彼此对齐 TextView 的相关文章

随机推荐