Issue
I want to display an EditText 15dp below the top of an ImageView. My ImageView is set to center horizontally and fill the parent RelativeLayout so the EditText's position is messed up. On some devices it shows up almost above the ImageView. Any ideas on how I can show it exactly 15dp below the top edge of the ImageView so that it's fully contained within the drawable?
Thank you!
<RelativeLayout
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_gravity="center">
<ImageView
android:id="@+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"/>
<EditText
android:id="@+id/edit_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/image_view"
android:gravity="center"
android:textColor="#FFFFFF"
android:background="#00000000"
android:textSize="39sp"
android:layout_marginTop="15dp"/>
</RelativeLayout>
Solution
Your layout seem to be correct you just need to use android:scaleType="fitStart" or centerCrop instead of android:adjustViewBounds="true" and set ImageView width and height to match_parent or 320dp
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320dp"
android:layout_height="320dp"
android:layout_gravity="center">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:scaleType="fitStart" />
<EditText
android:id="@+id/edit_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/image_view"
android:layout_marginTop="15dp"
android:background="#00000000"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="39sp" />
</RelativeLayout>
Answered By - Mostafa Gazar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.