0

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>
Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
djac
  • 187
  • 19
  • Pls. check https://stackoverflow.com/questions/9476662/how-to-set-android-layout-to-support-all-screen-sizes – user8256287 Aug 15 '17 at 07:07
  • @JaysonJohn, it tells about solution for different screen sizes. My question is about a fixed size rectangle as per code irrespective of screensize or device. – djac Aug 15 '17 at 07:12

3 Answers3

1

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" />
0

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"
 />
nivesh shastri
  • 430
  • 2
  • 13
0

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" />
user8256287
  • 177
  • 15