2014-01-30 56 views
0

我想知道是否有人可以解释我遇到的一个小问题。我试图让我的周围RelativeLayouts头,有以下几点:ImageViews和TextViews在相对布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:orientation="vertical" 
    android:background="#ffffff" 
    android:layout_height="fill_parent" >   

      <ImageView 
       android:id="@+id/newsImage" 
       android:layout_width="120dp" 
       android:layout_height="120dp" 
       android:layout_alignParentLeft="true" 
       android:background="#ffffff" > 
      </ImageView>    

      <TextView 
       android:id="@+id/newsSubtitle" 
       android:layout_height="fill_parent" 
       android:layout_width="200dp" 
       android:textColor="#0098bf" 
       android:layout_centerVertical="true" 
       android:layout_alignRight="@+id/newsImage" 
       android:textSize="18sp"> 
      </TextView> 

      <TextView 
       android:id="@+id/newsId" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:visibility="invisible" 
       android:textSize="0sp" > 
      </TextView>  
</RelativeLayout> 

正如我在RelativeLayouts理解它,你可以对齐孩子使用“alignParentLeft =‘真’”父(RelativeLayout的),你可以使用alignRight =“@ + id/childId”将每个孩子与其他孩子对齐。对于TextViews来说这似乎工作得很好,但是我无法让我的ImageViews正常工作 - 这就好像它们实际上似乎没有占用任何空间,因为TextView只是坐在图像的顶部,而不是对齐到图像的权利。

我在这里误解了一些东西吗?RelativeLayouts有不同的对齐图像/文本组合的方法吗?

回答

0

在您的textview上调用android:layout_below =“@ id/idofImageView”并将图像添加到ImageView。

编辑:对不起,你想让它正确的:android:align_toRightOf="@id/ImagevIEW"

+0

我已经在TextView中做了这个 'android:layout_alignRight =“@ + id/newsImage”' 我也尝试删除+号,但那也没用。 –

+0

+符号表示当您要调用现有的ID时,您正在创建一个新的ID。将来不要在引用另一个视图时使用加号。如果图像很大,那么textview会重叠,但代码仍然可以工作。尝试使用ic_launcher(应用程序图标)作为要检测的图像视图的来源。 –

0

使用此代码。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:orientation="vertical" 
    android:background="#ffffff" 
    android:layout_height="fill_parent" >   

      <ImageView 
       android:id="@+id/newsImage" 
       android:layout_width="120dp" 
       android:layout_height="120dp" 
       android:layout_alignParentLeft="true" 
       android:background="#ffffff" > 
      </ImageView> 

      <TextView 
       android:id="@+id/newsId" 
       android:layout_height="wrap_content" 
       android:layout_width="wrap_content" 
       android:visibility="gone" 
       android:textSize="0sp" > 
      </TextView> 

      <TextView 
       android:id="@+id/newsSubtitle" 
       android:layout_width="200dp" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentTop="true" 
       android:textColor="#0098bf" 
       android:textSize="18sp" /> 

</RelativeLayout> 
+0

我试图layout_height =“WRAP_CONTENT”和layout_height =“match_parent”,他们都给予同样的结果 - TextView的坐在ImageView的顶部:/ –

+0

尝试与一些类似android的android:layout_height =“100dp”或者包装内容的dp一样dp:layout_height =“wrap_content”' – InnocentKiller

+0

好吧,你到底想要怎样的内容。你想要在你的图片视图的下方或以上显示文本视图。 – InnocentKiller