2014-10-09 30 views
1

我有消息blocks.I要顯示的時間message.This的右下角是我的xml:展會時間

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


<LinearLayout 
    android:id="@+id/blocks" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/mes7" 
    android:layout_marginRight="6dp" 
    android:layout_marginLeft="6dp" 
    android:clickable="false"> 
<TextView 
    android:id="@+id/messageBar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" 
    android:layout_marginLeft="4dp" 
    android:layout_marginRight="6dp" 
    android:gravity="left" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:paddingTop="1dp" 
    android:text="Test Message" 
    android:typeface="sans" 
    android:textSize="14sp"/> 

<TextView 
    android:id="@+id/date" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="right|bottom" 
    android:layout_marginRight="5dp" 
    android:text="19:40" 
    android:textSize="10sp"/> 
</LinearLayout> 
</LinearLayout> 

我有短信,但沒有問題,當消息延長日期不showing.Here你可以看到:

enter image description here

還有一件事:我想要做的左緣緣,但我不能。

我該怎麼做?

回答

1

您必須包裝一個LinearLayout各地你的每一個TextViews,所以你可以在TextViews準確地使用andorid:gravity屬性。爲每個LinearLayouts定義一個寬度權重值,因此無論文本消息有多少行,您的時間都會一直顯示。爲此,必須在父佈局(根)中使用android:weightSum屬性,將LinearLayoutsandroid:layout_width值設置爲0dp,並使用android:layout_weight屬性將最後一個應用寬度空間在LinearLayouts中的每一箇中的百分比。這將確保您的寬度值始終是相對於設備屏幕寬度的常數。

試試這樣說:

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="0.8" 
    android:gravity="center" > 

    <TextView 
     android:id="@+id/messageBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:text="Test Message is this it has to be big to you can test it test here" 
     android:textSize="14sp" 
     android:typeface="sans" /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|right" 
    android:layout_weight="0.2" 
    android:clickable="false" > 

    <TextView 
     android:id="@+id/date" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:singleLine="true" 
     android:text="19:40" 
     android:textSize="12sp" /> 
</LinearLayout> 

+0

更新:我發現了問題。我認爲問題是「match_parent」,我們需要使用「 wrap_content「,但是當我們使用wrap_content時不顯示。如果我們使用」match_parent「結果:http://prntscr.com/4uqrwk – 2014-10-10 08:06:43

+1

再次更新:這是我的錯。我使用的是佈局參數。 – 2014-10-10 10:07:21

0

我建議設置的日期重量:

<TextView 
android:id="@+id/date" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_gravity="right|bottom" 
android:layout_marginRight="5dp" 
android:text="19:40" 
android:textSize="10sp" 
android:weight="1" /> 

那麼你可能會或可能不會需要設置消息寬度,以填補:

<TextView 
android:id="@+id/messageBar" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="left" 
android:layout_marginLeft="4dp" 
android:layout_marginRight="6dp" 
android:gravity="left" 
android:paddingLeft="5dp" 
android:paddingRight="5dp" 
android:paddingTop="1dp" 
android:text="Test Message" 
android:typeface="sans" 
android:textSize="14sp"/> 
+0

在這條線找到多個註釋: \t - 錯誤的方向是什麼?沒有指定方向,默認是水平的,但是這個佈局有多個子元素,其中至少有一個子元素。這個LinearLayout佈局或者它的LinearLayout父元素可能是無用的;將背景屬性傳遞給另一個視圖,我得到這個。 – 2014-10-09 13:21:17

+0

您的線性佈局'塊'不指定方向。不完全確定該佈局應該做什麼。 – RyPope 2014-10-09 13:29:34

+0

我該怎麼辦? – 2014-10-09 13:39:56