将视图放在顶部和两个视图之间

时间:2013-05-17 19:17:49

标签: android android-layout relativelayout android-view

试图找出克服这个小问题。

下面左侧是我正在尝试为应用实现的视图示例。在右边是我最终的观点。 Container

在我的xml模拟中,我决定使用RelativeLayout,但我无法让TextView在顶视图和底视图之间居中。

这里的参考是我的xml代码的代表:

 <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 个答案:

答案 0 :(得分: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>
相关问题