2013-04-05 58 views
1

我正在尝试制作一个列表,其中图像始终处于布局的右侧。同时,如果没有图像,我会喜欢主题文本来填充整个布局。Android布局文本在左边,图像在右边

这是我希望达到
当图像隐藏
enter image description here
有图像
enter image description here

电流输出什么:
在上的文字正面的形象。
enter image description here

<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:padding="6dip" android:layout_height="?android:attr/listPreferredItemHeight"> 
    <TextView 
     android:id="@+id/subject"   
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true" 
     android:text="Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange"/> 
    <TextView 
     android:id="@+id/cdate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"  
     android:layout_alignParentLeft="true" 
     android:layout_alignParentBottom="true" 
     android:textColor="#8000FF"  
     android:text="Date" /> 
    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"  
     android:layout_alignParentRight="true" 
     android:layout_alignRight="@id/subject" 
     android:src="@drawable/icon" /> 
</RelativeLayout> 

回答

2

尝试......欢呼:)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:padding="6dip" android:layout_height="?android:attr/listPreferredItemHeight"> 

<ImageView 
    android:id="@+id/icon" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:src="@drawable/icon" /> 

<TextView 
    android:id="@+id/subject"   
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"  
    android:text="Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange" 
    android:layout_toLeftOf="@id/icon"/> 
<TextView 
    android:id="@+id/cdate" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"  
    android:layout_alignParentLeft="true" 
    android:layout_alignParentBottom="true" 
    android:textColor="#8000FF"  
    android:text="Date" /> 

+0

甜感谢DrChivas – Eric 2013-04-05 02:40:43

+0

一种更有效的方式来将使用复合可绘制的textview。 – f2prateek 2013-04-05 02:58:03

1

,你应该这样做:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:padding="6dip" > 

    <ImageView 
     android:id="@+id/icon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/mark_ok" /> 

    <LinearLayout 
     android:id="@+id/leftblock" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/subject" 
     android:layout_alignTop="@+id/subject" 
     android:layout_toLeftOf="@+id/icon" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/subject" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange Apple Orange" /> 

     <TextView 
      android:id="@+id/cdate" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Date" 
      android:textColor="#8000FF" /> 
    </LinearLayout> 

</RelativeLayout> 
+0

你能点亮你的“应该”的理由吗?清洁器? – Hao 2015-03-18 12:29:59

+0

在包含2个块的相对布局中,如果指定,左侧块不会与右侧重叠:layout_toLeftOf =“” – 2015-03-19 08:18:30

+0

“@ +”非常重要,因为它指的是视图hasn'还没有创建:) – FrenchFalcon 2016-07-05 18:43:29

相关问题