at010
at010

Reputation: 137

Android ImageButton for various screen sizes

I am trying to create an image button which will cater for a variety of screens. However, I cannot get the image button to correctly fit a larger screen and instead shows a much smaller image on the image button.

What I have tried so far:

Is there anything wrong with my layout file below or is there certain image dimensions which are required?

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

<ScrollView
    android:id="@+id/homepageScrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" >

    <RelativeLayout
        android:id="@+id/homepageRelLayout2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="fill" >

    <ImageButton
        android:id="@+id/homepageImageButton"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_marginTop="40dp"
        android:src="@drawable/someImage" />

    </RelativeLayout>

</ScrollView>

</RelativeLayout>

Upvotes: 0

Views: 105

Answers (1)

cn123h
cn123h

Reputation: 2332

If you use ImageView + click listener, you will lose the button in/out effect. Maybe you can try to give your ImageButton a transparent background like this:

android:background="?android:selectableItemBackground"

Don't use @null or @android:color/transparent, they will lose the button effect as well.

Btw, android:selectableItemBackground doesn't work for old android version like 2.x

Upvotes: 1

Related Questions