简体   繁体   中英

Android Image Button Layout

Could someone please explain how android uses image button sizes? I seem to be getting odd behavior with my buttons. I have the following code as an example. I have two buttons that sit at the bottom of my layout. These buttons share 50% of the total width as they sit side-by-side. Within Abode PS, the two images (used for these two buttons) are actually 2" x 38" or 495x94 pixels. This size is of course larger than the available space in the layout. I am using edge effects on my buttons to give them definition. Android is cutting the edges off my buttons in order to center then in the available layout space. This particular layout that I am working on will only allow vertical orientation, in case that helps.

Thank you.

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

     <LinearLayout
        android:id="@+id/layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <ImageButton
            android:id="@+id/ImageButton1"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_marginLeft="1dip"
            android:layout_marginRight="1dip"
            android:layout_weight="1"
            android:background="#FF000000"
            android:src="@drawable/map4" >
        </ImageButton>


        <ImageButton
            android:id="@+id/ImageButton3"
            android:layout_width="0dip"
            android:layout_marginRight="1dip"
            android:layout_weight="1"
            android:background="#FF000000"
            android:src="@drawable/buy" 
            android:layout_height="wrap_content" 
            android:layout_marginLeft="1dip">
        </ImageButton>
    </LinearLayout>

</RelativeLayout>

try use the button and make it with empty text after this set the background .

or :

use the image button and put the source and the background the same image to get button exactly like the image


**you can use the selector to make some beauty for application buttons Google it it's easy to use ;)

Try using an ImageView and android:scaleType: http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType

Experiment the values available to see what is the best combination!

Then add a listener to behave like a button...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM