简体   繁体   中英

How to locate on view on the top and center of another one?

How to locate one view on the top and center of another one? So I want to have an ImageButton and TextView under it but first one to be in the center and on top of second one.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <TextView android:id="@+id/textView1" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="SOME TEXT HERE"
        android:layout_centerInParent="true" />
    <ImageButton android:src="@drawable/icon" android:id="@+id/imageButton1"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:layout_centerInParent="true" />
</RelativeLayout>

You can make use of FrameLayout to achieve this

Example

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