Reputation: 119
When I am loading an image(more specifically, an image of portrait shape) in an ImageView
that image is sometimes covering the Button
which is above the ImageView
. The ImageView
has layout_width
and layout_height
set to wrap_content
. My requirement is that the ImageView
will wrap content but, won't cover up the button. I don't want to hardcode pixel values.
layout:
<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="mg.colorfilters.ResultActivity$PlaceholderFragment" >
<Button
android:id="@+id/button1"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@color/red"
android:text="@string/string3"
android:textStyle="bold"
android:textColor="@color/white"
android:onClick="loadImageWithFilterOrSaveImage" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/abc_ab_bottom_solid_dark_holo"
android:contentDescription="@string/string4" />
</RelativeLayout>
Upvotes: 1
Views: 1129
Reputation: 821
You want your image to be at centre?
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
If yes, then may want to put your Button code below ImageView code, like
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/abc_ab_bottom_solid_dark_holo"
android:contentDescription="@string/string4" />
<Button
android:id="@+id/button1"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@color/red"
android:text="@string/string3"
android:textStyle="bold"
android:textColor="@color/white"
android:onClick="loadImageWithFilterOrSaveImage" />
This way the button will always be on top. If image is large, button will be visible on top of it. Use this solution only if you are OK with this behavior.
Upvotes: 1
Reputation: 131
you can use a scrollview inside the relative layout and use a linear layout in vertical orientation in the scrollview...then add your button and imageview in the linear layout.....I havent tried this but i think this will work :D
Upvotes: 0
Reputation: 8337
In Your Layout.xml
please insert android:layout_above="@+id/button1
line in <ImageView>
tag.
Upvotes: 0