0

我有两个文本视图,我想根据空间将第二个文本视图对齐到第一个文本视图的右侧或底部。结果应该是这样的:

第一种情况(单行):

Text1 一行 Text2

第二种情况(多行):

Text1 示例

两行
___________Text2

如您所见,在第一种情况下,第二个 textview 向右对齐,而在第二种情况下,它向右和底部对齐。我怎样才能在 xml 中实现该结果?

提前致谢!

4

2 回答 2

0

你是什​​么意思Text1比屏幕大?

这是我写的示例代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:background="@android:color/holo_green_dark"
    android:layout_height="wrap_content">

    <TextView
    android:layout_weight="1"
    android:gravity="bottom|left"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="your text more than 1 line"/>

    <TextView
        android:gravity="center|bottom"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Text2"/>

</LinearLayout>

为了让 Text1 在左边,Text2 在右边,使用LinearLayout并设置orientation:"horizontal"

在此处输入图像描述

让我知道,如果这不能回答你想要的。

与您的问题相关,您只需要使用TextView'sgravity并且如果值为Textview动态,则必须在您的 java 文件中创建条件。

于 2016-03-03T17:50:53.583 回答
0

您可以将FlowLayout ViewGroup用作父级。

https://github.com/ApmeM/android-flowlayout

于 2016-03-03T17:34:28.140 回答