2016-11-23 76 views
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:layout_height="match_parent"> 

    <Button 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="70dp" 
      android:layout_height="55dp" 
      android:text="nope" 
      android:id="@+id/cancel_arrive" 
      android:onClick="selectNotGoing" 
      /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:weightSum="1"> 

     <TextView 
      android:id="@+id/attendingEventInListviewRow" 
      android:layout_width="match_parent" 
      android:layout_height="28dp" 
      android:text="eventsName" 
      android:height="30sp" 
      android:textSize="22sp" 
      android:gravity="right" 
      android:tag="eventsName" 
      /> 

     <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="eventDayOfTheWeek" 
     android:textColor="#000000" 
     android:id="@+id/eventDayOfTheWeekTxt" 
      android:gravity="right" 

      /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:text="eventTime" 
     android:textColor="#000000" 
     android:id="@+id/eventTimeTxt" 
     android:gravity="right" 
     /> 

    </LinearLayout> 


</LinearLayout> 

我試圖谷歌問題和實施解決方案,我在這裏找到。沒什麼幫助。上面的代碼是我當前的XML。我需要eventNameeventDayOfTheWeekeventTime留在右側。無法對齊佈局中的文本

我也嘗試清理該項目並重建它,但它保持不變。

(在預覽文本是在右側,發射後進入左側)

推出之前(在預覽):http://prntscr.com/db0f7t

(佈局:http://prntscr.com/db0ekp 發射後是列表視圖中的一行)

+0

如果我運行它,文本在TextView中是右對齊的。你能指定你的情況發生了什麼? – weibeld

+0

我也在預覽時看到右側的文字,但是當我啓動應用程序時,它會顯示在左側。 – Jack

+0

嘗試爲TextView添加不同的背景顏色(例如'android:background =「#FF0000」'),以便更好地瞭解發生了什麼,然後可能會在問題中發佈屏幕截圖。 – weibeld

回答

1

預覽顯示您的佈局沒有信息,它將被充氣,假定爲「批發」佈局。但是您的XML代碼是容器中的一部分(ListView),它可能設置了layout_widthwrap_content(或固定值)。你的ListView應該有match_parent(也可能是它的父母)。顯示更多代碼,尤其是對於ActivityFragment,如果您正在使用。

+0

我已經從wrap_content更改了列表視圖的佈局寬度,以匹配父級,並且它工作。謝謝。 – Jack