TextView над изображением в макете - PullRequest
1 голос
/ 03 марта 2012

Я использую этот макет для моего экрана:

    <?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_gravity="top|center" android:layout_marginTop="-10dp"/>

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/propfile" 
        android:layout_gravity="top|center"/>    
</LinearLayout>

и я хочу добавить TextView на экран, который будет над imageView2.

и когда я добавляю его в xml, он показывается под изображением. что мне нужно сделать, чтобы иметь возможность нанести TextView на изображение.

Ответы [ 3 ]

4 голосов
/ 03 марта 2012

Попробуйте это:

    <?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 голосов
/ 26 сентября 2013

Вот альтернатива, в вашем XML-файле:

 <TextView android:layout_width="wrap_content"
           android:layout_height="wrap_content" 
           android:text="text" 
           android:layout_centerInParent="true"
           android:layout_above="idofyourImage"
       /> 

Надеюсь, это поможет

0 голосов
/ 03 марта 2012

Вы можете добавить еще один LinearLayout, где находится второе изображение, например:

<?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_gravity="top|center" android:layout_marginTop="-10dp"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text Goes Here" />
        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/propfile" 
            android:layout_gravity="top|center"/>    
    </LinearLayout>
</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...