2017-02-19 60 views
0

我有簡單recycler_view_item,我已經得到了應表現出一定的量(像左)文本視圖 recycler_view_item的TextView:TextView的內容對準左

<TextView 
    android:text="500" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/debtors_item_leftamount" 
    android:textSize="@dimen/debtors_left_amount_size" 
    android:layout_weight="1" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintRight_toLeftOf="@+id/debtors_item_arrow" 
    android:layout_marginEnd="32dp" 
    android:textAlignment="textStart" 
    android:layout_marginRight="32dp"/> 

是否有人知道如何使它是對齊左邊就像在正確的形象?

我已經試過

android:textAlignment="textStart" 
android:textAlignment="viewStart" 
android:gravity=start, left, even top or any other 

什麼也沒有改變。

Image

回答

0

這應該工作

android:layout_width="match_parent" 

android:gravity="left" 
+0

我無法使用match_parent,因爲此TextView的父項是整個recyclerView項目,並且還有其他元素 –

+0

但您給了我間接建議。我已經使用原始大小的寬度(例如50),然後將textAlignment設置爲textStart並且它正常工作! –

0

這個怎麼樣?

您纏繞回收視圖的內容以線性佈局如下::

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_parent" 
    android:weightSum="10" 
    android:gravity="center"> 

    //use the weight to define the layout_width="0" and layout_weight of the child elements 
    //define weight as required as matching your requirements. 

    //example below for Image View you are using 
    <ImageView 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1.5" 
    android:src="@drawable/image" 
    android:gravity="center"> 

</LinearLayout> 

這會給你固定響應的寬度和高度從設備的角度爲好。您將能夠使用重力來定義元素的位置。