2013-05-17 54 views
1

试图找出克服这个小问题。在顶部和两个视图之间放置视图

下面的左侧是我试图为应用程序实现的视图示例。右侧是我将要结束的观点。 Container

在我的XML模拟了,我已经决定要使用RelativeLayout,但我不能让TextView到顶部和底部的观点之间为中心。

仅供参考这里是我的XML代码represenation:

<RelativeLayout 
    android:layout_width:"match_parent" 
    android:layout_height:"wrap_content"> 
    <ImageView 
     android:id="@+id/BlackImage" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:scaleType="centerCrop" 
     android:layout_alightParentTop="true" 
     android:layout_centerHorizontal="true"/> 
    <ImageView 
     android:id="@+id/RedImage" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:scaleType="centerCrop" 
     android:layout_below="@+id/BlackImage" 
     android:layout_centerHorizontal="true"/> 
    <TextView 
     android:id="@+id/TextView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/BlackImage" 
     android:layout_centerHorizontal="true"/> 
</RelativeLayout> 

任何想法,我缺少的是什么,或者如何改变让我想要什么?

+1

我想我会尝试'FrameLayout'的是,由于'RelativeLayout'相当用于沿着边缘对齐的视图。无论如何,你可以尝试一个负边距或填充。 – Trinimon

+0

尝试下面的链接希望它会帮助你: - duggu

回答

0

试试下面链接希望它会帮助你: -

TextView above Image view in a layout

Android listview item display text over image using array adapter

how to put text under image view

<?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="match_parent" 
     android:orientation="vertical" android:background="@drawable/tmp" > 


     <ImageView 
      android:id="@+id/imageView1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/uph" 
      android:layout_marginTop="-10dp"/> 

     <RelativeLayout android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="top|center"> 

      <ImageView 
       android:id="@+id/imageView2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:src="@drawable/propfile" 
      /> 

      <TextView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="text" 
       android:layout_centerInParent="true" 
      /> 
     </RelativeLayout> 
    </LinearLayout> 
+0

不知道我可以有多个'layout_gravity'选项。你每天学习新的东西!要尝试一下,谢谢你的链接! – edc598

相关问题