Reputation: 9
I need put the button above image in this relative layout but appear in the top how can i do? So I need image and above the button. any help?
<RelativeLayout style="@style/row50percent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgProfileBackground"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:src="@drawable/bg_profile"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/imgProfile"
android:adjustViewBounds="true"
android:gravity="center_vertical"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/logo"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/choose_picture"
android:id="@+id/buttonSelectPicture"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/btn_change_picture"
android:textColor="#FFFFFF"
android:layout_gravity="center_horizontal|center"/>
</RelativeLayout>
And Styles is
<style name="row50percent">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">0dp</item>
<item name="android:orientation">vertical</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:layout_weight">1</item>
</style>
Upvotes: 0
Views: 1385
Reputation: 3906
Put ImageView
and Button
inside RelativeLayout
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.MainActivity" >
<ImageView
android:id="@+id/imgProfile"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:src="@drawable/ab" />
<Button
android:id="@+id/buttonSelectPicture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/imgProfile"
android:layout_alignRight="@+id/imgProfile"
android:layout_alignTop="@+id/imgProfile"
android:layout_marginTop="62dp"
android:text="Cose Picture"
android:textColor="#FFFFFF" />
</RelativeLayout>
output
Upvotes: 0
Reputation: 624
could be:
<RelativeLayout style="@style/row50percent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgProfileBackground"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:src="@drawable/bg_profile"/>
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/imgProfile"
android:adjustViewBounds="true"
android:gravity="center_vertical"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/logo"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal"
android:gravity="top|center"
>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/choose_picture"
android:id="@+id/buttonSelectPicture"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:background="@drawable/btn_change_picture"
android:textColor="#FFFFFF"
android:layout_gravity="center_horizontal|center"/>
</LinearLayout>
</RelativeLayout>
Upvotes: 1