Chris Muench
Chris Muench

Reputation: 18318

Android imageView very tiny

I am using a relative layout and attempting to have an image at the top with a text field and a button.

The image ends up bring really tiny:

Tiny image

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.phppointofsale.phppointofsale.StoreUrlFragement" >

    <Button
        android:id="@+id/continue_to_store"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="118dp"
        android:text="@string/continue_to_store" />

    <EditText
        android:id="@+id/store_url"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/continue_to_store"
        android:layout_alignLeft="@+id/continue_to_store"
        android:layout_alignRight="@+id/continue_to_store"
        android:layout_marginBottom="60dp"
        android:ems="10"
        android:hint="@string/store_url_hint"
        android:inputType="textUri" />

    <ImageView
        android:id="@+id/logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="19dp"
        android:contentDescription="@string/logo_desc"
        android:src="@drawable/logo" />

</RelativeLayout>

Upvotes: 0

Views: 561

Answers (2)

bowman han
bowman han

Reputation: 1135

By default, contents of an ImageView control are of a certain size-usually the size of the graphic dimensions. They are also bounded by their layout_width and layout_height attributes. You can also specify minimum and maximum height and width attributes using a dimension resource (dp, px, etc.) For more information on dimensions, see the Android SDK documentation on Resource Dimensions.

In XML, these properties would appear within your ImageView control as:

android:minHeight="50dp"
android:minWidth="50dp"
android:maxHeight="150dp"
android:maxWidth="150dp"

Here we are specifying that the control should have a specific minimum and maximum size. Note that when used alone, specifying these sizes does not preserve the aspect ratio of the image, and therefore it can look squished, squashed, or otherwise not ideal.

If you’re working with ImageView control’s in your Java code, you can also set the min and max sizes of your ImageView control programmatically using the setMinimumHeight(), setMaxHeight(), setMinimumWidth(), and setMaxWidth() methods of the ImageView class.

Upvotes: 0

Sushil
Sushil

Reputation: 8478

In you layout for your imageview, you have mentioned following:

android:layout_width="wrap_content"
android:layout_height="wrap_content"

This is causing the image to take actual size, which is small in your case. either replace with a larger image or change the width and height in layout to give some value like this:

android:layout_width="200dp"
android:layout_height="200dp"

Upvotes: 1

Related Questions