简体   繁体   中英

How do I set the position of an image view in a relative layout in Android?

I'm trying to position an image below a TextView in a RelativeLayout but it doesn't work. when i set its position using android:layout_below . This is my xml

<?xml version="1.0" encoding="utf-8"?>

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

<TextView 
android:id="@+id/app_details_1" 
android:text="@string/app_details_1" 
android:textColor="#347"
android:gravity="center"
android:textSize="9pt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>  

<ImageView 
android:id="@+id/logo"
android:src="@drawable/secs"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@+id/appdetails_1" <!-- I'm setting it here -->
/>

</RelativeLayout>

Instead it just places the image at the top left of the screen. How do I position it? Is layout_below a wrong positioning code?

There's a mistake in your xml. Must be

android:layout_below="@id/app_details_1"

应该没问题,但是首先尝试通过对textView使用layout_alignParentTop =“ true”来确保textView位于顶部,并查看其是否有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM