ImageButtons Size and placement do not work in Eclipse

ISSUE: It seems I can not make my ImageButtons appear in the right place or have the right size.

PLATFORM : Eclipse with Android API 16

PROBLEM: My RelativeLayout is 600x800 and my ImageButtons are 194x64, but when I put them in the editor, they are twice as many as they should be. See link to image.

enter image description here

My XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:android1="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/main_portal_bg" > <RelativeLayout android1:layout_width="353dp" android1:layout_height="758dp" android1:layout_marginLeft="115dp" android1:layout_marginTop="29dp" android1:background="#000000" > </RelativeLayout> <ImageButton android1:id="@+id/new_customer_button_selector" android1:layout_width="194dp" android1:layout_height="64dp" android1:layout_marginTop="89dp" android1:contentDescription="@string/back_button_desc" android1:background="@drawable/new_customer_button_selector" /> <ImageButton android1:id="@+id/returning_customer_button_selector" android1:layout_width="194dp" android1:layout_height="64dp" android1:layout_alignParentLeft="true" android1:layout_below="@+id/new_customer_button_selector" android1:contentDescription="@string/back_button_desc" android1:src="@drawable/returning_customer_button_selector" /> <ImageButton android1:id="@+id/redeem_coupon_button_selector" android1:layout_width="194dp" android1:layout_height="64dp" android1:layout_alignParentLeft="true" android1:layout_below="@+id/returning_customer_button_selector" android1:contentDescription="@string/back_button_desc" android1:src="@drawable/redeem_coupon_button_selector" /> <ImageButton android1:id="@+id/info_button_selector" android1:layout_width="194dp" android1:layout_height="64dp" android1:layout_alignParentLeft="true" android1:layout_below="@+id/redeem_coupon_button_selector" android1:contentDescription="@string/back_button_desc" android1:src="@drawable/info_button_selector" /> </RelativeLayout> 

RESEARCH: I tried using ScaleType for FitXY by setting MaxHeight and MinHeight and using android: background instead of android: src. The only way I was able to reduce them was to use the graphics editor to resize by holding down the SHIFT key and dragging the lower right corner. This also, unfortunately, makes them automatically align to the bottom of the layout, and when I try to move them, they return to their original size, and all other buttons are shuffled around the layout. Editing XML only helps me with this.

QUESTIONS: Each time I try to move a button in a graphical editor, all other buttons are shuffled in random order around the screen. Why is this happening?

I set the width to 194dp and the height to 64dp. Changing these values ​​does nothing. Why doesn't this affect the actual width and height of my ImageButton?

When using a graphical editor to resize a button by holding SHIFT and dragging an angle, this does not change the width and height values ​​in XML, but simply adds fields. See Final XML below:

  <ImageButton android1:id="@+id/new_customer_button_selector" android1:layout_width="194dp" android1:layout_height="64dp" android1:layout_alignParentBottom="true" android1:layout_alignRight="@+id/returning_customer_button_selector" android1:layout_marginBottom="408dp" android1:layout_marginRight="86dp" android1:layout_marginTop="89dp" android1:background="@drawable/new_customer_button_selector" android1:contentDescription="@string/back_button_desc" /> 

HERE IS MY FINAL GOAL:

enter image description here

Please tell me how I can get there. This simple thing should be simpler.

+4
source share
1 answer

After reading the information provided at developer.android.com/guide/practices/screens_support.html, I now understand 4 different types of screen density. Thanks to CaseyB for this link.

I calculated a screen density of about 160, after using the utility that I found in http://members.ping.de/~sven/dpi.html .

My problem was that the default AVD created by AVD Manager has an LCD density set to 240 (high).

After setting to 160, my project will display with the correct button sizes.

I left all my drawings in the drawables folder, since I am developing for 1 screen resolution and density. If I decided to use a different tablet, then I could use other folders.

TIP: Do not depend on the Eclipse graphical editor to align or calibrate resources. I am not sure if this is completely accurate. I use old XML editing and run the project method when trying to adjust the size and spacing.

0
source

Source: https://habr.com/ru/post/1439417/


All Articles