У меня есть следующий вид:
И я хочу, чтобы это выглядело так:
ВВо-первых, фон зеленого ImageButton находится в верхнем левом углу.А во втором фоне зеленый ImageButton находится в центре.(Фоновое изображение имеет размер зеленого квадрата)
Вот мой XML-код:
<?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>
Где
android:background="@drawable/btncall"
относится к btncall.xml, которыйВыглядит так:
<?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>
Я новичок в Android, поэтому, если вы видите лучший способ создать этот вид, пожалуйста, скажите мне.
10x много, Райан.
В Addtion это часть кода в основном файле Java:
...
//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); ...