Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show ImageView top of RelativeLayout

I have placed an ImageView at the top of a RelativeLayout but the image does not show at the top of the page. I searched the internet and I added android:scaleType="fitStart" and the problem was solved, but image gets more space in page because when I add a second image below this image, the second image shows at the center of the page! What is the problem? How can i solve this? I tried using a LinearLayout which produces same result.

<?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">

<ImageView
    android:id="@+id/registerAction"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:scaleType="fitStart"
    android:src="@drawable/register_action" />

<ImageView
    android:id="@+id/registerLogo"
    android:src="@drawable/app_pass"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_below="@id/registerAction"/>
<EditText
    android:id="@+id/pass1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/registerLogo"
    android:paddingTop="15dp"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    android:inputType="textPassword"
    android:hint="@string/pass1"
    android:gravity="right"/>
<EditText
    android:id="@+id/pass2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/pass1"
    android:paddingTop="15dp"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    android:inputType="textPassword"
    android:hint="@string/pass2"
    android:gravity="right"/>
<Button
    android:id="@+id/btn"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/pass2"
    android:paddingRight="10dp"
    android:paddingLeft="10dp"
    android:paddingTop="30dp"/>
</RelativeLayout>

Thanks.Cheers

EDIT: and another question How can i padding Button 30dp in below of EditText? when i changed PaddingTop of Button not changed position of Button.

like image 720
SensorS Avatar asked Mar 22 '23 10:03

SensorS


1 Answers

// try this
<?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">

    <ImageView
        android:id="@+id/registerAction"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/register_action" />

    <ImageView
        android:id="@+id/registerLogo"
        android:src="@drawable/app_pass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/registerAction"/>
    <EditText
        android:id="@+id/pass1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/registerLogo"
        android:paddingTop="15dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:inputType="textPassword"
        android:hint="@string/pass1"
        android:gravity="right"/>
    <EditText
        android:id="@+id/pass2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/pass1"
        android:paddingTop="15dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:inputType="textPassword"
        android:hint="@string/pass2"
        android:gravity="right"/>
    <Button
        android:id="@+id/btn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/pass2"
        android:paddingRight="10dp"
        android:paddingLeft="10dp"
        android:paddingTop="30dp"/>
</RelativeLayout>
like image 173
Haresh Chhelana Avatar answered Apr 06 '23 18:04

Haresh Chhelana