I have the following view:
And I want it to look like this:
In the first, the background of the green ImageButton is in the upper left corner. And in the second background, the green ImageButton is in the center. (The background image is the size of a green square)
Here is my XML code:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageButton android:id="@+id/dialer" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/btncall" android:scaleType="centerInside"/> <Button android:id="@+id/sendSMS" android:layout_alignParentTop="true" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Send SMS"/> <Button android:id="@+id/four" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:id="@+id/shutDownDevice" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Turn Off"/> </RelativeLayout>
Where
android:background="@drawable/btncall"
refers to btncall.xml, which is as follows:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/phone_down" android:state_pressed="true" /> <item android:drawable="@drawable/phone_down" android:state_focused="true" /> <item android:drawable="@drawable/phone_up" /> </selector>
I am starting with Android, so if you see a better way to create this wiew, plz tell me.
10x a lot, Ryan.
In Addtion, this is part of the code in the main Java file:
... //Get width and Height of screen Display display = getWindowManager().getDefaultDisplay(); int halfStageWidth = display.getWidth()/2; int halfStageHeight = display.getHeight()/2; //Get an instance of the Dialer button ImageButton btnDialer = (ImageButton) findViewById(R.id.dialer); Button btnSendSMS = (Button) findViewById(R.id.sendSMS); btnSendSMS.setWidth(halfStageWidth); btnSendSMS.setHeight(halfStageHeight); Button btnShutDownDevice = (Button) findViewById(R.id.shutDownDevice); btnShutDownDevice.setWidth(halfStageWidth); btnShutDownDevice.setHeight(halfStageHeight); Button B4 = (Button) findViewById(R.id.four); B4.setWidth(halfStageWidth); B4.setHeight(halfStageHeight); ...
source share