djac
djac

Reputation: 197

Showing incorrect imageview size in spite of correct parameters

I have the following xml to display an image. The issue is, when the page is loading the image view rectangle is not as per the given sizes. How can I rectify it? For example I need a 150 x 150 rectangle as per the code.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="2dp"
        android:layout_marginTop="2dp"
        android:layout_marginRight="2dp"
        android:layout_marginBottom="2dp"
        android:id="@+id/table_two">
        <TableRow
            android:padding="2dp"
            android:layout_width="150dp"
            android:layout_height="150dp">
            <ImageView
                android:layout_width="150dp"
                android:layout_height="150dp"
                android:layout_weight="1"
                app:srcCompat="@android:drawable/picture_frame"
                android:id="@+id/ui_imageView_browse"
                android:layout_gravity="center"
                android:scaleType="fitXY" />
        </TableRow>
    </TableLayout>
</LinearLayout>

Upvotes: 0

Views: 52

Answers (3)

user8256287
user8256287

Reputation: 177

try this

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

    <ImageView
        android:id="@+id/ui_imageView_browse"
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:layout_weight="1"
        android:scaleType="fitXY"
        app:srcCompat="@android:drawable/picture_frame" />

Upvotes: 0

nivesh shastri
nivesh shastri

Reputation: 440

Define your Image View like below:

<ImageView
  android:layout_width="150dp"
  android:layout_height="150dp"
  app:srcCompat="@android:drawable/picture_frame"
  android:id="@+id/ui_imageView_browse"
  android:layout_gravity="center"
 />

Upvotes: 0

soumyadip001
soumyadip001

Reputation: 96

remove this part from ImageView

android:layout_gravity="center"

So, your ImageView should be as follows

<ImageView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:layout_weight="1"
    app:srcCompat="@android:drawable/picture_frame"
    android:id="@+id/ui_imageView_browse"
    android:scaleType="fitXY" />

Upvotes: 1

Related Questions