2012-10-29 58 views
0

我對xml的一些細節不太好,而且我找不到下一個問題的解決方案。在一行中對齊元素xml

我有一個ListView。一個行被定義旁邊似XML代碼:

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

     <TextView 
      android:id="@+id/date" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:textColor="#ff888888" 
      android:textSize="10dp" 
      android:paddingRight="5dp" 
      android:paddingTop="5dp" 
      android:paddingBottom="5dp" 
      android:paddingLeft="5dp" 
      android:text="02 OCT" 
      android:textStyle="bold" 
     /> 


     <TextView 
      android:id="@+id/title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

      android:textColor="#ff000000" 
      android:textSize="14dp" 
      android:singleLine="true" 
      android:ellipsize="end" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp" 
      android:paddingTop="5dp" 
      android:paddingBottom="5dp" 
      android:text="GIRLFRIEND COFFE AT STARBUCKS COFFE" 
      android:maxWidth="250dip" 
     /> 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

      android:background="@drawable/icon_clip" 
      android:layout_marginTop="5dp" 
      android:layout_marginBottom="5dp" 
      android:id="@+id/img_posted_check" 
     /> 
     <TextView 
      android:id="@+id/relleno" 
      android:layout_width="0dip" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:textColor="#ff000000" 
      android:textSize="14dp" 
      android:singleLine="true" 
      android:ellipsize="end" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp" 
      android:paddingTop="5dp" 
      android:paddingBottom="5dp" 
      android:text="" 
     /> 

     <TextView 
      android:id="@+id/amount" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#ff000000" 
      android:textSize="14dp" 
      android:paddingLeft="5dp" 
      android:paddingTop="5dp" 
      android:paddingBottom="5dp" 
      android:paddingRight="5dp" 
      android:text="$13.34" 
     /> 
</LinearLayout> 

如果文本很短,我可以看到OK: enter image description here

但是,如果文字說明是這麼長時間,它需要所有的空間,直到極限窗口和裁剪用「...」彈出價格和剪輯標記: enter image description here

我能做到這一點,只有當我不使用夾子增加重量屬性的文本視圖與標題ID (@ + id/title),沒有id爲'relleno'的佈局。

+0

什麼是你想實現準確?你的'TextView'被設置爲'android:singleLine =「true」',如果你刪除這行,那麼你的文本將換行到下一行。 – jnthnjns

+0

我想要下一個元素:日期,說明,剪輯圖像(可選)和價格(右對齊)。全部只在一行中。 – moskis

回答

1

我想這是你想要

<?xml version="1.0" encoding="utf-8"?> 

<TextView 
    android:id="@+id/date" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:paddingBottom="5dp" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:paddingTop="5dp" 
    android:text="02 OCT" 
    android:textColor="#ff888888" 
    android:textSize="10dp" 
    android:textStyle="bold" /> 

<TextView 
    android:id="@+id/title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@+id/img_posted_check" 
    android:layout_toRightOf="@+id/date" 
    android:ellipsize="end" 
    android:maxWidth="250dip" 
    android:paddingBottom="5dp" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:paddingTop="5dp" 
    android:singleLine="true" 
    android:text="GIRLFRIEND COFFE AT STARBUCKS COFFE" 
    android:textColor="#ff000000" 
    android:textSize="14dp" /> 

<ImageView 
    android:id="@+id/img_posted_check" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" 
    android:layout_marginTop="5dp" 
    android:layout_toLeftOf="@+id/relleno" 
    android:background="@drawable/ic_launcher" /> 

<TextView 
    android:id="@+id/relleno" 
    android:layout_width="0dip" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@+id/amount" 
    android:ellipsize="end" 
    android:paddingBottom="5dp" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:paddingTop="5dp" 
    android:singleLine="true" 
    android:text="" 
    android:textColor="#ff000000" 
    android:textSize="14dp" /> 

<TextView 
    android:id="@+id/amount" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:paddingBottom="5dp" 
    android:paddingLeft="5dp" 
    android:paddingRight="5dp" 
    android:paddingTop="5dp" 
    android:text="$13.34" 
    android:textColor="#ff000000" 
    android:textSize="14dp" /> 

</RelativeLayout> 
+0

不完全。該圖標必須與說明文字一起。 – moskis

0

然後你可以替換的TextView ImageView的東西..,使用此

<TextView 
     android:id="@+id/img_posted_check" 
     android:layout_width="300dp" 
     android:gravity="center" 
     android:layout_height="wrap_content" 
     android:drawableLeft="@drawable/ic_launcher" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp" 

     android:text="hiiii" />