0

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

第一种情况(单线):

文本1一行文本2

第二种情况(多线):

文本1例如用

两行
___________Text2

正如你所看到的,在第一种情况下,第二个textv视图与右侧对齐,而在第二种情况下,它与右侧和底部对齐。我怎么能在XML中实现这个结果?

在此先感谢!

+0

你是什么意思,Text1放大那个屏幕? –

回答

0

什么你的意思是文本1大于屏幕?

这是我写的示例代码:

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

以适应文本1左,文本2是正确的,使用LinearLayout并设置orientation:"horizontal"

enter image description here

让我知道,如果这没有回答你想要的。

与您的问题相关,您只需要玩TextViewgravity如果Textview的值为动态,则必须在您的java文件中创建条件。

+0

谢谢你的回答,这不是我正在寻找的。让我解释一下,如果第一个文本没有填充屏幕的宽度,我希望第二个textview与第一个textview的右侧对齐。而且,如果第一个文本视图中有多行,则在右下角。 – FVod

+0

检查我的更新答案。我补充说,1行和文本2仍然在底部。让我知道如果仍然没有你需要的东西。 –

+0

谢谢,看看我的例子。当多行时,那么我需要text2在右下角,不只是在text1的右侧:( – FVod