newbieee
newbieee

Reputation: 450

Android studio renders same layout differently

I'm trying to use some portions of my previous project in my new project but I have encountered with a strange problem. My new project renders the same layout differently from the previous project. Here is the layout.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center" >

<ImageView
    android:id="@+id/id1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/image"
    />
</FrameLayout>

And here are the two different results:

Layout 1

enter image description here

Layouts are 100% same but in the first one, ImageView holds a larger space than the image. In the second one, ImageView wraps the image, no extra space around the image. I want to use second one but what am I missing?

Target sdk, min sdk etc. are all the same.

Thanks in advance.

Upvotes: 2

Views: 354

Answers (2)

CristianGuerrero
CristianGuerrero

Reputation: 1293

Try this:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
    android:id="@+id/id1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:src="@drawable/image"/>
</FrameLayout>

Upvotes: 0

Orcun Sevsay
Orcun Sevsay

Reputation: 1473

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:orientation="vertical"
             android:layout_gravity="center"
             android:paddingRight="50dp"
             android:paddingLeft="50dp">

    <ImageView
        android:id="@+id/id1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image"
        />
</FrameLayout>

You may want to try this code above. Adjust the paddings as you want!

Upvotes: 1

Related Questions