相对于彼此对齐TextView [英] Align TextViews relative to each other

查看:70
本文介绍了相对于彼此对齐TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have two TextView. First TextView contains dynamic text, that can be small and big. Second TextView contains static small text. Second TextView should be located to right of first TextView.

这是应该如何工作的:

  • 当第一个文本很大时:
  • 并且当文本较小时:
  • when first text is big:
  • and when text is small:

如何进行此布局?使用相对或线性布局时,第一个TextView包含大文本-第二个文本只是从屏幕上消失了.

How can I make this layout? With Relative or Linear layouts when first TextView contains big text - second text simply disappeared from screen.

推荐答案

尝试以下

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

Add the following dependency to your build.gradle file:

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>

输出

带有大文本的输出

这篇关于相对于彼此对齐TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆