I am trying to align buttons like simple calculator
But when i align buttons like that when i run it buttons can shift from desired location.
I can't understand what is problem.
here is code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:gravity="fill_vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button4"
android:layout_alignBottom="#+id/button4"
android:layout_alignLeft="#+id/button14"
android:layout_toLeftOf="#+id/button12"
android:onClick="#string/_onclick"
android:text="#string/_4" />
<Button
android:id="#+id/button16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button4"
android:layout_toLeftOf="#+id/button5"
android:onClick="#string/_onclick"
android:text="#string/_9" />
<Button
android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button6"
android:layout_alignParentBottom="true"
android:layout_marginBottom="16dp"
android:onClick="#string/_onclick"
android:text="#string/_" />
<Button
android:id="#+id/button8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/button7"
android:layout_alignLeft="#+id/button11"
android:layout_toLeftOf="#+id/button9"
android:onClick="#string/_onclick"
android:text="#string/_1" />
<Button
android:id="#+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button7"
android:layout_toRightOf="#+id/button1"
android:onClick="#string/_onclick"
android:text="#string/_3" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button7"
android:layout_alignLeft="#+id/button4"
android:onClick="#string/_onclick"
android:text="#string/_jam" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button12"
android:layout_alignBottom="#+id/button12"
android:layout_alignLeft="#+id/button5"
android:onClick="#string/_onclick"
android:text="#string/_menha" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button16"
android:layout_alignBottom="#+id/button16"
android:layout_alignLeft="#+id/button3"
android:onClick="#string/_onclick"
android:text="#string/_zarb" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button5"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
android:onClick="#string/_onclick"
android:text="#string/_taghsim" />
<Button
android:id="#+id/button14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button11"
android:layout_toLeftOf="#+id/button12"
android:onClick="#string/_onclick"
android:text="#string/_7" />
<Button
android:id="#+id/button15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button13"
android:layout_alignLeft="#+id/button12"
android:layout_toLeftOf="#+id/button13"
android:onClick="#string/_onclick"
android:text="#string/_8" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button7"
android:layout_alignLeft="#id/button12"
android:layout_alignTop="#id/button10"
android:layout_toLeftOf="#+id/button10"
android:onClick="#string/_onclick"
android:text="#string/_2" />
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button3"
android:layout_alignBottom="#+id/button3"
android:layout_toLeftOf="#+id/button3"
android:layout_toRightOf="#+id/button1"
android:onClick="#string/_onclick"
android:text="#string/c" />
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button14"
android:layout_alignLeft="#+id/button14"
android:layout_alignParentBottom="false"
android:layout_alignParentRight="false"
android:layout_alignRight="#+id/button15"
android:layout_alignWithParentIfMissing="false"
android:layout_centerInParent="false"
android:onClick="#string/_onclick"
android:text="#string/ce" />
<Button
android:id="#+id/button17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button7"
android:layout_alignBottom="#+id/button7"
android:layout_alignRight="#+id/button10"
android:layout_toRightOf="#+id/button9"
android:onClick="#string/_onclick"
android:text="#string/_dot" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_alignParentTop="true"
android:layout_marginLeft="17dp"
android:layout_marginTop="59dp"
android:textSize="20sp"
tools:ignore="SpUsage" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/button10"
android:layout_alignBaseline="#+id/button12"
android:layout_alignBottom="#+id/button12"
android:layout_alignLeft="#+id/button16"
android:layout_below="#id/button16"
android:layout_toLeftOf="#id/button4"
android:onClick="#string/_onclick"
android:text="#string/_6" />
<Button
android:id="#+id/Button01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/button8"
android:layout_toLeftOf="#+id/button17"
android:onClick="#string/_onclick"
android:text="#string/_0" />
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button10"
android:layout_toLeftOf="#+id/button13"
android:onClick="#string/_onclick"
android:text="#string/_5" />
this is screenshot of my problems:
http://i39.tinypic.com/xm04lz.jpg
http://i42.tinypic.com/ibgmk3.jpg
please help me how can i solve the problem
Why are you making your life so difficult? Stop this alignment madness and use LinearLayouts. Create a LinearLayout and put the 5 rows of buttons inside, with each row as LinearLayout. Then use the layout_weight parameter to add them the same (or desired) width.
Example:
<LinearLayout>
<LinearLayout>
Button Button Button Button
</LinearLayout>
<LinearLayout>
Button Button Button Button
</LinearLayout>
....
</LinearLayout>
Related
How to fill the background efficiently with white text and black background.when i fill the backgound using this code in xml in Button filed
android:background="#c6010101"
Button code is here
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/OpenBraces"
android:id="#+id/buttonOB"
android:layout_above="#+id/button1"
android:layout_toRightOf="#+id/button1"
android:layout_toEndOf="#+id/button1"
android:background="#c6010101"
android:textColor="#FFFFFCFC" />
Full code is here.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:inputType="textCapCharacters"
android:digits="0123456789=+-*^/{}.xX"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<!-- Footer Ends -->
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:layout_above="#+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/One"
android:id="#+id/button1"
android:layout_above="#+id/button4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Two"
android:id="#+id/button2"
android:layout_alignTop="#+id/button1"
android:layout_toRightOf="#+id/button1"
android:layout_toEndOf="#+id/button1"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Three"
android:id="#+id/button3"
android:layout_alignBottom="#+id/button2"
android:layout_toRightOf="#+id/button2"
android:layout_toEndOf="#+id/button2"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Plus"
android:id="#+id/buttonPlus"
android:layout_above="#+id/button6"
android:layout_toRightOf="#+id/button3"
android:layout_toEndOf="#+id/button3"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="4"
android:layout_above="#+id/linearLayout3"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Four"
android:id="#+id/button4"
android:layout_above="#+id/button7"
android:layout_toLeftOf="#+id/button8"
android:layout_toStartOf="#+id/button8"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Five"
android:id="#+id/button5"
android:layout_above="#+id/button8"
android:layout_alignLeft="#+id/button2"
android:layout_alignStart="#+id/button2"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Six"
android:id="#+id/button6"
android:layout_alignTop="#+id/button5"
android:layout_toRightOf="#+id/button5"
android:layout_toEndOf="#+id/button5"
android:background="#64010001"
android:textColor="#FFFFFCFC"
android:singleLine="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Minus"
android:id="#+id/buttonMinus"
android:layout_above="#+id/button9"
android:layout_toRightOf="#+id/button6"
android:layout_toEndOf="#+id/button6"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout4"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Seven"
android:id="#+id/button7"
android:layout_above="#+id/button0"
android:layout_toLeftOf="#+id/button8"
android:layout_toStartOf="#+id/button8"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Eight"
android:id="#+id/button8"
android:layout_alignBottom="#+id/button7"
android:layout_alignLeft="#+id/button5"
android:layout_alignStart="#+id/button5"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Nine"
android:id="#+id/button9"
android:layout_alignTop="#+id/button8"
android:layout_toRightOf="#+id/button8"
android:layout_toEndOf="#+id/button8"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Multiply"
android:id="#+id/buttonMul"
android:layout_alignBottom="#+id/button9"
android:layout_toRightOf="#+id/button9"
android:layout_toEndOf="#+id/button9"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="4"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Dot"
android:id="#+id/buttonDot"
android:background="#64010001"
android:textColor="#FFFFFCFC"
android:layout_below="#+id/button7"
android:layout_toLeftOf="#+id/button8"
android:layout_toStartOf="#+id/button8" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Zero"
android:id="#+id/button0"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/button7"
android:layout_alignRight="#+id/button8"
android:layout_alignEnd="#+id/button8"
android:background="#64010001"
android:textColor="#FFFFFCFC" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Equal"
android:id="#+id/buttonEqual"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/button0"
android:layout_toEndOf="#+id/button0" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Divide"
android:id="#+id/buttonDiv"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/button9"
android:layout_toEndOf="#+id/button9"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:orientation="horizontal"
android:weightSum="4">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/VariableX"
android:layout_weight="1"
android:id="#+id/buttonVarX"
android:layout_above="#+id/button1"
android:layout_toLeftOf="#+id/button2"
android:layout_toStartOf="#+id/button2"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/OpenBraces"
android:id="#+id/buttonOB"
android:layout_above="#+id/button1"
android:layout_toRightOf="#+id/button1"
android:layout_toEndOf="#+id/button1"
android:background="#c6010101"
android:textColor="#FFFFFCFC" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/CloseBraces"
android:id="#+id/buttonCB"
android:layout_above="#+id/button2"
android:layout_toRightOf="#+id/button2"
android:layout_alignRight="#+id/button3"
android:layout_alignEnd="#+id/button3"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/Power"
android:id="#+id/buttonPow"
android:backgroundTint="#c6010101"
android:textColor="#FFFFFCFC"
android:layout_above="#+id/buttonPlus"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</LinearLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="40dp"
android:id="#+id/buttonBS"
android:src="#android:drawable/ic_media_rew"
android:background="#c6010101"
android:contentDescription="#string/Back"
android:layout_above="#+id/linearLayout0"
android:layout_alignRight="#+id/webView"
android:layout_alignEnd="#+id/webView" />
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/webView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/editText"
android:layout_alignRight="#+id/linearLayout1"
android:layout_alignEnd="#+id/linearLayout1"
android:layout_above="#+id/buttonBS" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/buttonSolution"
android:id="#+id/buttonSol"
android:layout_above="#+id/linearLayout0"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
then it android:background not only fill the button area but also fills the outer area of the button. At this area the button click is not working because it is not part of the Button but it looks like as it is part of the button as you can see in this pic
The empty space out side of the button is shown in this picture. i want to show it with this shape with white text and black button color.
i have also try to use android:backgroundTint="#c6010101" it shows in android as i want but it does not work on mobile.
it can be resolved by giving the shape. we can do it by using the select
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/button_1_selected"
android:state_pressed="true"/>
<!-- focused state -->
<item android:drawable="#drawable/button_1_focused"
android:state_focused="true"/>
<!-- default state -->
<item android:drawable="#drawable/button_1_normal"/>
</selector>
write this code and save with extension .xml (btn_black.xml) in drawable folder of E:\My-Application\app\src\main\res\drawable
and in your button xml code add this code
also write the code of focused, normal and selected in xml and save in the same folder(drawable) with the the name as you have given in the selector code. in this code file name will be
button_1_focused.xml
button_1_normal.xml
button_1_selected.xml
button_1_normal.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/button_1_normal_background"/>
<corners android:radius="10dip"/>
</shape>
similer for other .
Also see this side http://www.codeproject.com/Articles/1006843/An-Efficient-Way-to-Make-Button-Color-Change-on-An
i want create a password activity to get password then show main activity i make the xml file like this
this is my xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="ir.sheikhoo.safesms.LoginActivity"
android:background="#373737" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/button3"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/button1"
android:layout_centerHorizontal="true"
android:text="8" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_marginTop="21dp"
android:layout_toLeftOf="#+id/button2"
android:text="7" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_toRightOf="#+id/button2"
android:text="9" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button2"
android:layout_toLeftOf="#+id/button2"
android:text="4" />
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button2"
android:layout_toLeftOf="#+id/button3"
android:text="5" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button5"
android:layout_alignBottom="#+id/button5"
android:layout_alignLeft="#+id/button3"
android:text="6" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button4"
android:layout_below="#+id/button4"
android:text="1" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button7"
android:layout_alignBottom="#+id/button7"
android:layout_toLeftOf="#+id/button6"
android:text="2" />
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button6"
android:layout_alignTop="#+id/button8"
android:text="3" />
<Button
android:id="#+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button7"
android:layout_alignRight="#+id/button9"
android:layout_below="#+id/button8"
android:text="0" />
</RelativeLayout>
this is image
or this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="ir.sheikhoo.safesms.LoginActivity"
android:background="#373737" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_alignParentRight="true"
android:text="9" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button5"
android:layout_alignBottom="#+id/button5"
android:layout_alignLeft="#+id/button3"
android:text="6" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button4"
android:layout_below="#+id/button4"
android:text="1" />
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button6"
android:layout_alignTop="#+id/button8"
android:text="3" />
<Button
android:id="#+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button7"
android:layout_alignRight="#+id/button9"
android:layout_below="#+id/button8"
android:text="0" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_alignLeft="#+id/editText1"
android:text="7" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button5"
android:layout_alignBottom="#+id/button5"
android:layout_alignLeft="#+id/button1"
android:text="4" />
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button2"
android:layout_below="#+id/button2"
android:text="5" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button7"
android:layout_alignBottom="#+id/button7"
android:layout_alignLeft="#+id/button5"
android:text="2" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp"
android:text="8" />
</RelativeLayout>
but I want the button width change when the screen change size and fill all screen
Try this,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="ir.sheikhoo.safesms.LoginActivity"
android:background="#373737" >
<EditText
android:id="#+id/editText1"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button2"
android:layout_alignBottom="#+id/button2"
android:layout_alignParentRight="true"
android:text="9" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button5"
android:layout_alignBottom="#+id/button5"
android:layout_alignLeft="#+id/button3"
android:text="6" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button4"
android:text="1" />
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_marginRight="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button6"
android:layout_alignTop="#+id/button8"
android:text="3" />
<Button
android:id="#+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"
android:layout_below="#+id/button8"
android:text="0" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button2"
android:text="7" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button5"
android:layout_alignBottom="#+id/button5"
android:text="4" />
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignLeft="#+id/button2"
android:layout_below="#+id/button2"
android:text="5" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button7"
android:layout_alignBottom="#+id/button7"
android:layout_centerHorizontal="true"
android:layout_alignLeft="#+id/button5"
android:text="2" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true"
android:layout_marginTop="31dp"
android:text="8" />
</RelativeLayout>
You can use LinearLayout's "weight" attribute for this design. So create a new folder duplicate layout in this directory (create if doesn't exist in) : /res/layout-land.
I just show you the first line of the three buttons, i.e. button 7, 8 and 9:
<LinearLayout android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_below="#+id/editText">
<Button android:id="#+id/btn7
android:layout_weight="1"
... />
<Button android:id="#+id/btn8
android:layout_weight="1"
... />
<Button android:id="#+id/btn9
android:layout_weight="1"
... />
</LinearLayout>
Don't forget to set configChanges="orientation" in manifest.
I didn't know how to call it but I'll try to explain what I mean -
How can I build an interface in android that can print some letters and then the user can pick some letters and form a word or a sentence.
Example: for those of you who know "Draw Something", when you have to guess what your friends drew, you have some scrambled letters from which you can pick some and form a sentence.
Here is an image of that:
http://i.gyazo.com/033b5c9a2864c6a17d7445e0a1a3079e.png
How can I achieve that?
Something like this?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:ems="10" >
<requestFocus />
</EditText>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText1"
android:layout_centerHorizontal="true" >
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="A" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/button1"
android:text="B" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/button2"
android:text="C" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/button3"
android:text="D" />
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/button1"
android:text="E" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button2"
android:layout_alignTop="#+id/button5"
android:text="F" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button3"
android:layout_alignTop="#+id/button6"
android:text="G" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button4"
android:layout_alignTop="#+id/button7"
android:text="H" />
</RelativeLayout>
</RelativeLayout>
I am new to Android Programming(started yesterday, infact) and I cannot, for the life of me, get ScrollView to scroll. I have a bunch of buttons which won't all fit on the screen, so I tried to add a scroll function. However, this doesn't work. I am running an emulator if that helps. Here is my XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".UnleashedMainPageActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/unleashed_Main" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:text="#string/choose_Mod" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignRight="#+id/textView2"
android:layout_below="#+id/textView2"
android:text="Applied Energistics" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button4"
android:layout_alignRight="#+id/button4"
android:layout_below="#+id/button4"
android:text="Buildcraft" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_alignRight="#+id/button1"
android:layout_below="#+id/button1"
android:text="Computer Craft" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button2"
android:layout_alignRight="#+id/button2"
android:layout_below="#+id/button2"
android:text="Ender Storage" />
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button3"
android:layout_alignRight="#+id/button3"
android:layout_below="#+id/button3"
android:text="Equivalent Exchange 3" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button5"
android:layout_alignRight="#+id/button5"
android:layout_below="#+id/button5"
android:text="ExtraBiomes/Biomes O' Plenty" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button6"
android:layout_alignRight="#+id/button6"
android:layout_below="#+id/button6"
android:text="Factorization" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button7"
android:layout_alignRight="#+id/button7"
android:layout_below="#+id/button7"
android:text="Forestry" />
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button8"
android:layout_alignRight="#+id/button8"
android:layout_below="#+id/button8"
android:text="IndustrialCraft 2" />
<Button
android:id="#+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button9"
android:layout_alignRight="#+id/button9"
android:layout_below="#+id/button9"
android:text="MineFactory Reloaded" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button10"
android:layout_alignLeft="#+id/button4"
android:layout_alignTop="#+id/button4"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
replace :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".UnleashedMainPageActivity" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/unleashed_Main" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:text="#string/choose_Mod" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignRight="#+id/textView2"
android:layout_below="#+id/textView2"
android:text="Applied Energistics" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button4"
android:layout_alignRight="#+id/button4"
android:layout_below="#+id/button4"
android:text="Buildcraft" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_alignRight="#+id/button1"
android:layout_below="#+id/button1"
android:text="Computer Craft" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button2"
android:layout_alignRight="#+id/button2"
android:layout_below="#+id/button2"
android:text="Ender Storage" />
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button3"
android:layout_alignRight="#+id/button3"
android:layout_below="#+id/button3"
android:text="Equivalent Exchange 3" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button5"
android:layout_alignRight="#+id/button5"
android:layout_below="#+id/button5"
android:text="ExtraBiomes/Biomes O' Plenty" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button6"
android:layout_alignRight="#+id/button6"
android:layout_below="#+id/button6"
android:text="Factorization" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button7"
android:layout_alignRight="#+id/button7"
android:layout_below="#+id/button7"
android:text="Forestry" />
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button8"
android:layout_alignRight="#+id/button8"
android:layout_below="#+id/button8"
android:text="IndustrialCraft 2" />
<Button
android:id="#+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button9"
android:layout_alignRight="#+id/button9"
android:layout_below="#+id/button9"
android:text="MineFactory Reloaded" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
at first you don't have close tag for RelativeLayout.
and if you want scrollview work then you have to insert enough views in scrollview for fill screen height
I want to align the buttons as shown bellow,
for this, I used relative layout. But The buttons are not fit to correct position due to the buttons relations with others. I don't know other possible methods for this.. Please Help me if there another suitable methods for this arrangement of buttons..
You can design as much as u want
First of all make one
Large size Relative layout
add four buttons to that layout at each cornet of layout.
then add button to exact middle of two corner buttons
try this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#00F" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="180dp"
android:layout_height="180dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#FFF" >
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Button" />
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Button" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Button" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/button7"
android:text="Button" />
</RelativeLayout>
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="#+id/button10"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />
<Button
android:id="#+id/button11"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Button" />
<Button
android:id="#+id/button12"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Button" />
<Button
android:id="#+id/button13"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Button" />
<Button
android:id="#+id/button14"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="Button" />
<Button
android:id="#+id/button15"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button14"
android:layout_alignParentRight="true"
android:text="Button" />
<Button
android:id="#+id/button16"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
</RelativeLayout>
</RelativeLayout>
I worked on your solution and made a similar looking layout. But I couldn't get exactly what you are looking for, bcoz your Image sample is some what in a square manner whereas the device screen is in rectangular shape.
Anyway try this out,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout android:id="#+id/first_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 1"/>
<Button android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 2"
android:layout_alignParentRight="true"/>
<Button android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text=" 3"/>
<Button android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text=" 4"/>
<Button android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text=" 5"/>
<Button android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:text=" 6"/>
<Button android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text=" 7"/>
<Button android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text=" 8"/>
<RelativeLayout android:id="#+id/first_layout"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:paddingLeft="40dip"
android:paddingRight="40dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 1"/>
<Button android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 2"
android:layout_alignParentRight="true"/>
<Button android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text=" 3"/>
<Button android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text=" 4"/>
<Button android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text=" 5"/>
<Button android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:text=" 6"/>
<Button android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text=" 7"/>
<Button android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text=" 8"/>
<RelativeLayout android:id="#+id/first_layout"
android:paddingTop="50dip"
android:paddingBottom="50dip"
android:paddingLeft="40dip"
android:paddingRight="40dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 1"/>
<Button android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" 2"
android:layout_alignParentRight="true"/>
<Button android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text=" 3"/>
<Button android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text=" 4"/>
<Button android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text=" 5"/>
<Button android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:text=" 6"/>
<Button android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text=" 7"/>
<Button android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text=" 8"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Screenshot,