Reputation: 10609
I have a nexus 7 tablet with 1900 x 1200 resolution. I try to create an ImageButton
with wrap_content
but the created ImageButton
is much too big and i dont know why.
This is the layout i use:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/gradient" >
<ImageButton
android:id="@+id/main_button_fog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/custom_button_fog"
android:contentDescription="@string/imageview_description"
android:scaleType="centerInside" />
</RelativeLayout>
When i start my Application it looks like that:
As a reminder: the width of nexus 7 tablet is 1200 px. The with of my image is 397 px so it should be much smaller. Why is the Image loaded here so big?
Upvotes: 0
Views: 45
Reputation: 16224
I didn't try this, but i think that it can work. But if i can say a thing, put the value of width and height as wrap_content if you want that image will have the maximum dimensions is not useful. If you want to scale the image as the size of the screen you have to use also Java part. Tell me if this doesn't work by the way.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/gradient" >
<ImageButton
android:id="@+id/main_button_fog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="android:color/transparent"
android:src="@drawable/custom_button_fog"
android:contentDescription="@string/imageview_description"
android:scaleType="fitCenter" />
</RelativeLayout>
Upvotes: 1