简体   繁体   中英

Button on top of an imageview and a linear layout

I have three items in my activity. An image view, button, and linear layout. I want to make the button sit on top of the linear layout and image view.

A sample output is like this:

~~~~~~~~~~~~~~~~~~~~~~~~
|       IMAGE VIEW     |
|       ~~~~~~~~       |
|-------|BUTTON|-------|
|       ~~~~~~~~       |
|     linear layout    |
|______________________|

I've tried coding it using this XML though, the problem is that the button is not rendering on top of the button and linear layout as what i wanted to happen in the example. Is there a way for this to be implemented?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="package">


<LinearLayout

    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    android:layout_weight="3">


    <ImageView

        android:layout_height="wrap_content"
        android:id="@+id/imageView3"
        android:layout_gravity="center_horizontal"
        android:background="#AAAAAA"
        android:src="@drawable/write"
        android:layout_width="match_parent"
        android:layout_weight="1" />


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button2"
        android:layout_gravity="center_horizontal"
   />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button"
        android:layout_gravity="center_horizontal"
        android:layout_weight="2" />

</LinearLayout>

谷歌设计库中的协调器布局是为这种类型“com.android.support:design:22.2.0”制作的

I figured it out by creatine a relative layout where in the button will be set in the center using android:layout_centerInParent="true" then I created a linear layout with android:weightSum="2" then i equally divided the linearLayout with an imageView and another linearLayout.

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_centerVertical="true"
android:layout_height="fill_parent">


<LinearLayout
    android:layout_below="@+id/app_bar"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:weightSum="2"
    android:layout_height="fill_parent">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView3"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_weight="1"
        android:background="#DDF43F" />

<LinearLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">


</LinearLayout>

</LinearLayout>
<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:background="@drawable/button_custom_login"/>
</RelativeLayout>

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