2016-12-16 104 views
1

下面是一张图片来帮助我解释我的问题:TextView不从左侧开始

黑框是整个屏幕。红色框是TextView。绿色是文字。当我运行我的代码时,它看起来像左边的屏幕,但我希望它看起来像它在右边。 (左起开始)

enter image description here

这里是TextView代码:

<TextView 
    android:id="@+id/info_ruta" 
    android:layout_width="256dp" 
    android:layout_height="80dp" 
    android:layout_marginEnd="8dp" 
    android:layout_marginStart="8dp" 
    android:layout_marginTop="8dp" 
    android:text="@string/info_sumary" 
    android:textColor="#FFF" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/day_seven_id" /> 

当试图添加android:gravity="left"="start"它不与我的问题有所帮助。我在这里错过了什么?

+1

使用'android:layout_width =“match_parent”'并确保容器也应该具有match_parent,如果问题仍然存在,请在整个布局后留言 –

+0

什么是父布局?尝试发布您的完整布局。 –

+0

@PavneetSingh照顾我的问题!谢谢! “回答”,如果你想我接受并赞扬。 – Carlton

回答

2

use android:layout_width="match_parent"代替固定的宽度android:layout_height="80dp"所以这将是

<TextView 
    android:id="@+id/info_ruta" 

    android:layout_width="match_parent"        

    android:layout_height="80dp" 
    android:layout_marginEnd="8dp" 
    android:layout_marginStart="8dp" 
    android:layout_marginTop="8dp" 
    android:text="@string/info_sumary" 
    android:textColor="#FFF" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/day_seven_id" /> 

match_parentandroid:width意味着覆盖由所述父容器所占据的整个宽度。

2

在XML的属性上使用android:layout_width="match_parent"android:gravity="left"

这对父母来说是非常重要的。

+0

谢谢!有用!会upvote,但不能“接受”对不起@pavneetSingh首先评论。但再次感谢。 – Carlton

+0

没问题,谢谢 –