pmb
pmb

Reputation: 2327

why there is some space in this layout?

I use this code for making this layout.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="20dp"
                android:background="@android:color/transparent">
    <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_centerInParent="true"
            android:background="@drawable/rounded_white_bg">
        <EditText
                android:id="@+id/login"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:background="@drawable/dialog_edittex"
                android:layout_margin="10dp"/>
        <EditText
                android:id="@+id/password"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:layout_margin="10dp"
                android:background="@drawable/dialog_edittex"/>
        <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:textColor="@android:color/black"
                android:text="AAAAAAAAAAAA"
                android:layout_gravity="center"
                android:textSize="20sp"
                />
        <ImageView
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:src="@drawable/dialog_button_bg"/>

    </LinearLayout>


</RelativeLayout>

rouded_whiite.bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffff" />
    <corners
            android:radius="20dp"/>
</shape>

But when I do this I have see this result. As you can see there is some margin below of red button. I didn't set any margin or something but there is some space there. What should I do here for getting exact result as in fist image.

enter image description here

Upvotes: 0

Views: 818

Answers (5)

Akbarsha
Akbarsha

Reputation: 2568

If your using drawable for imageview as .png or .jpg use the following drawable for your image may be it would help. save this as backgroung_bg.xml or anything else as you wish

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
    <shape >
        <corners android:bottomLeftRadius="20dp"
            android:bottomRightRadius="20dp"
            android:topLeftRadius="0dp"
            android:topRightRadius="0dp"/>
        <solid android:color="#CF4647"/>
        <padding android:left="5dp"
            android:top="5dp"
            android:right="5dp"
            android:bottom="5dp"/>
    </shape>
</item>

when you apply this you would get following warning just ignore and run it. if you need gradient type of color ask me

The graphics preview in the layout editor may not be accurate: Different corner sizes are not supported in Path.addRoundRect. (Ignore for this session)

Upvotes: 0

Harshit Rathi
Harshit Rathi

Reputation: 1862

Use :

android:layout_centerHorizontal="true"

instead of

android:layout_centerInParent="true"

and remove margin from bottom...

Upvotes: 1

ishu
ishu

Reputation: 1332

Try This

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="20dp"
                android:background="@android:color/transparent">
    <LinearLayout
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:background="@drawable/rounded_white_bg">
        <EditText
                android:id="@+id/login"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:background="@drawable/dialog_edittex"
                android:layout_margin="10dp"/>
        <EditText
                android:id="@+id/password"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:layout_margin="10dp"
                android:background="@drawable/dialog_edittex"/>
        <TextView
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:textColor="@android:color/black"
                android:text="AAAAAAAAAAAA"
                android:layout_gravity="center"
                android:textSize="20sp"
                />
        <ImageView
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:src="@drawable/dialog_button_bg"/>

    </LinearLayout>


</RelativeLayout>

Upvotes: 0

GrIsHu
GrIsHu

Reputation: 23638

Remove the margin from your RelativeLayout and make your LinearLayout gravity android:layout_centerHorizontal="true"

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
           android:background="@android:color/transparent">
<LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_centerHorizontal="true"
        android:background="@drawable/rounded_white_bg">

Upvotes: 1

Tamilselvan Kalimuthu
Tamilselvan Kalimuthu

Reputation: 1532

  <LinearLayout
        android:layout_height="wrap_content"

it is because of this. remove the imageview from the linear layout and set in the relative layout and give property as alignparent bottom and for the linear layout give alignparent top and above the image view property,

Upvotes: 0

Related Questions