android computer app calculator design - android

Ok so the problem basicly is I want to make my android calculator UI look like this can anybody give any suggestions or help? Much appreciated!
Desktop Calculator App
and the code:
<LinearLayout 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:orientation="vertical"
android:weightSum="10"
>
<TextView
android:id="#+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/zero"
android:textSize="50sp"
android:minHeight="100dp"
android:gravity="bottom|end"
android:layout_weight="2.5"
/>
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="5"
android:orientation="horizontal"
android:layout_weight="2.5"
>
<Button
android:id="#+id/number7"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/seven"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/number8"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/eight"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/number9"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/nine"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/dividesign"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/divide"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/signpercent"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/percent"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="5"
android:orientation="horizontal"
android:layout_weight="2.5"
>
<Button
android:id="#+id/number4"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/four"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/number5"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/five"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/number6"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/six"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/multiplysign"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/multiply"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/onedividexsign"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/onedividex"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutrest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="2.5">
<RelativeLayout
android:id="#+id/layout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/number1"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:text="#string/one"
android:onClick="findWhichButtonClickedOn"
/>
<!-- android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>-->
<Button
android:id="#+id/number2"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:text="#string/two"
android:layout_toRightOf="#+id/number1"
android:layout_toEndOf="#+id/number1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/zero"
android:layout_below="#+id/number1"
android:layout_alignLeft="#+id/number1"
android:layout_alignStart="#+id/number1"
android:layout_alignEnd="#+id/number2"
android:layout_alignRight="#+id/number2"
android:clickable="true"
android:onClick="findWhichButtonClickedOn"
/>
</RelativeLayout>
<LinearLayout
android:id="#+id/layout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_centerHorizontal="true"
android:weightSum="2">
<Button
android:id="#+id/number3"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:text="#string/three"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/dot"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:text="#string/dot"
android:layout_weight="1"
android:onClick="findWhichButtonClickedOn"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/layout4"
android:layout_toEndOf="#+id/layout4"
android:orientation="vertical">
<Button
android:id="#+id/minus"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:text="#string/minus"
android:onClick="findWhichButtonClickedOn"
/>
<Button
android:id="#+id/plussign"
android:layout_width="71dp"
android:layout_height="wrap_content"
android:text="#string/add"
android:onClick="findWhichButtonClickedOn"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/layout5"
android:layout_toEndOf="#+id/layout5"
android:orientation="vertical">
<Button
android:id="#+id/equalsign"
android:layout_width="71dp"
android:layout_height="fill_parent"
android:text="#string/equals"
android:onClick="findWhichButtonClickedOn"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
but I can't seem to do it. This is my code and what mine looks like so far:
MyCalcAppSoFar``

Related

"<" string in xml file

I could not build my project in the android studio.
the problem was ":app:mergeDebugResources" Error,
after a while I found this error is caused by android:text"<"
attribute in the XML file.after changing "<" character, the problem was solved.
Is there any meaning for "<" String_character in XML language?
The XML file is : (black lines of the code)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:orientation="horizontal">
<Button
android:id="#+id/btn_clearEntity"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="CE"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_clear"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="C"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_delete"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="<"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_division"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="/"
android:textColor="#000000"
android:textSize="20dip" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:orientation="horizontal">
<Button
android:id="#+id/btn_7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="7"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_8"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="8"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_9"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="9"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_multiplication"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="X"
android:textColor="#000000"
android:textSize="20dip" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18">
<Button
android:id="#+id/btn_4"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="4"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_5"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:baselineAligned="false"
android:text="5"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_6"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="6"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_minus"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="-"
android:textColor="#000000"
android:textSize="20dip" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:orientation="horizontal">
<Button
android:id="#+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="1"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="2"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="3"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_plus"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="+"
android:textColor="#000000"
android:textSize="20dip" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.18"
android:orientation="horizontal">
<Button
android:id="#+id/btn_sign"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="-/+"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="0"
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_point"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="."
android:textColor="#000000"
android:textSize="20dip" />
<Button
android:id="#+id/btn_equal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="="
android:textColor="#000000"
android:textSize="20dip" />
</LinearLayout>
</LinearLayout>
and:
[[image of error]
I am assuming that you are wondering how to get a < or a > in the text of a view.
For a less than <
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="<"/>
For a greater than >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=">"/>
https://www.w3schools.com/html/html_entities.asp

How to arrange layouts with many view controls

I want the screen like this :
![my screen schema][1] [1]: http://i.stack.imgur.com/PBt0i.png
How should be the layout?
I have given some fixed width and height but this is not good practice please help me in designing this screen.
For more details below is my xml file
<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="match_parent"
android:background="#android:color/background_light"
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=".QuestionBankActivity" >
<RelativeLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:background="#drawable/orangewood"
android:gravity="top"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="3dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp"
android:background="#drawable/blue_gray_back"
android:gravity="center_vertical|center_horizontal"
android:padding="5dp"
android:paddingTop="1dp"
android:text="#string/QuesPalet"
android:textColor="#android:color/background_light"
android:typeface="serif" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentRight="true"
android:layout_marginRight="22dp"
android:padding="5dp"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="invisible" />
<Chronometer
android:id="#+id/chronometer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentRight="true"
android:layout_marginRight="22dp"
android:padding="5dp"
android:textSize="20sp"
android:textStyle="bold"
android:visibility="invisible" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/button1"
android:padding="5dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignLeft="#+id/textView3"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:gravity="center|center_horizontal|center_vertical"
android:padding="5dp"
android:textColor="#android:color/background_light"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="334dp"
android:layout_below="#+id/linearLayout2"
android:paddingBottom="10dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#+id/radioGroup1"
android:layout_centerHorizontal="true"
android:weightSum="4"
android:background="#drawable/orangewood"
android:orientation="horizontal" >
<Button
android:id="#+id/reviewBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:background="#drawable/blue_gray_back"
android:gravity="left"
android:textColor="#FFFFFF"
android:typeface="serif" />
<Button
android:id="#+id/clearBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/blue_gray_back"
android:layout_weight="1"
android:textColor="#FFFFFF"
android:typeface="serif" />
<Button
android:id="#+id/saveNextBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#drawable/blue_gray_back"
android:layout_weight="1"
android:gravity="left"
android:textColor="#FFFFFF"
android:typeface="serif" />
</LinearLayout>
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/webView1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="horizontal"
android:weightSum="4" >
<RadioButton
android:id="#+id/radio0"
android:layout_marginLeft=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="20sp"
android:gravity="fill_vertical"
android:textStyle="bold"
android:textColor="#000000"
android:button="#drawable/custom_radio"
/>
<RadioButton
android:id="#+id/radio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#drawable/custom_radio"
android:textSize="20sp"
android:gravity="fill_vertical"
android:textStyle="bold"
android:textColor="#000000"/>
<RadioButton
android:id="#+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="#drawable/custom_radio"
android:textSize="20sp"
android:gravity="fill_vertical"
android:textStyle="bold"
android:textColor="#000000" />
<RadioButton
android:id="#+id/radio3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/custom_radio"
android:textSize="20sp"
android:gravity="fill_vertical"
android:textStyle="bold"
android:layout_weight="1"
android:textColor="#000000" />
</RadioGroup>
</RelativeLayout>
Thanks!!
Note that I am using scale to width of views but this is bad coding because it will not fit to various screens.Please correct me if I am wrong! feel free to ask any details regarding this problem..
its a dummy code check this and create your own :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearLayout1" />
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout3"
android:layout_alignParentLeft="true" >
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RadioButton" />
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="RadioButton" />
</LinearLayout>
First you need relative layout and Linearlayout... and scrollLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/white" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="36dp"
android:background="#e66b7a">
//put here btn and textview
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4.12"
android:background="#color/white" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/imageView1"
android:background="#color/white"
android:paddingTop="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="3dp" >
<WebView
android:id="#+id/webcontain"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
//put here radio button
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.08"
android:background="#drawable/topbar" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/footer"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/footer"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/footer"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/imageButton9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/footer"
android:gravity="center"
android:orientation="vertical" >
<Button
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
And this is code for 4 radio button.. this will fit in all size of screens
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbuttodn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbuttdtgyodn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="#+id/okbuttrtodn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="SET"
/>
</LinearLayout>
</LinearLayout>
Use like below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Medium Text1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Medium Text2"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:id="#+id/weblayout1"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_below="#+id/layout1"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="1"
android:text="Webview"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:id="#+id/rdbtndlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/weblayout1"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Rd1" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Rd2" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Rd3" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Rd4" />
</LinearLayout>
<LinearLayout
android:id="#+id/btnlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rdbtndlayout"
android:orientation="horizontal" >
<Button
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1" />
<Button
android:id="#+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button2" />
<Button
android:id="#+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button3" />
</LinearLayout>
<LinearLayout>
</RelativeLayout >
You can place your webview and radiogroups inside respective layouts
Try this..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/first_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_txt"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
android:layout_weight="1"
android:gravity="center"
android:text="Button" />
<Chronometer
android:id="#+id/chronometer1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txt1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="TextView"
android:textSize="20dp" />
</LinearLayout>
<WebView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="fill_vertical"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="fill_vertical"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="fill_vertical"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/radio3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="fill_vertical"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
</RadioGroup>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal" >
<Button
android:id="#+id/reviewBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/clearBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/saveNextBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
you can use this.
<LinearLayout 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:background="#android:color/background_light"
android:orientation="vertical"
tools:context=".QuestionBankActivity" >
<RelativeLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_marginTop="5dp"
android:background="#ff0000"
android:gravity="top"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="3dp"
android:layout_marginLeft="3dp"
android:layout_marginTop="3dp"
android:background="#000"
android:gravity="center_vertical|center_horizontal"
android:padding="5dp"
android:paddingTop="1dp"
android:text="QuesPalet"
android:textColor="#android:color/background_light"
android:typeface="serif" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_margin="3dp"
android:gravity="center|center_horizontal|center_vertical"
android:padding="5dp"
android:text="TextView"
android:textColor="#android:color/background_light"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".8"
android:paddingBottom="10dp"
android:scrollbars="vertical" />
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:orientation="horizontal" >
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="1"
android:textColor="#ff0000" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2"
android:textColor="#ff0000" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3"
android:textColor="#ff0000" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4"
android:textColor="#ff0000" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:orientation="horizontal" >
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

Custom Alert button overlapping

Ok i successfully created a custom alert and when i ran it the format is the same as in xml but after re-running it for the nth time suddenly the buttons overlap and I dont know how to fix it so can you pls help me out on this?.
alert.xml(output should be):
wrong output:
xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#595959">
<EditText
android:id="#+id/orderQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/b3"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number" />
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/b4"
android:layout_alignParentLeft="true"
android:text="1" />
<Button
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/orderQuantity"
android:layout_toRightOf="#+id/b4"
android:text="2" />
<Button
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/b4"
android:layout_centerHorizontal="true"
android:text="3" />
<Button
android:id="#+id/b4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/b2"
android:text="4" />
<Button
android:id="#+id/b5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/b2"
android:layout_toLeftOf="#+id/b3"
android:text="5" />
<Button
android:id="#+id/b6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/b5"
android:layout_alignBottom="#+id/b5"
android:layout_alignLeft="#+id/b3"
android:text="6" />
<Button
android:id="#+id/b7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/b4"
android:layout_toLeftOf="#+id/b5"
android:text="7" />
<Button
android:id="#+id/b8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/b4"
android:layout_toRightOf="#+id/b4"
android:text="8" />
<Button
android:id="#+id/b9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/b6"
android:layout_below="#+id/b6"
android:text="9" />
<Button
android:id="#+id/b0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/b8"
android:layout_toLeftOf="#+id/b9"
android:text="0" />
<Button
android:id="#+id/addCart"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/b0"
android:layout_alignParentLeft="true"
android:layout_below="#+id/b7"
android:layout_toLeftOf="#+id/b0"
android:text="ADD" />
<Button
android:id="#+id/cancel"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/b0"
android:layout_alignRight="#+id/b9"
android:layout_below="#+id/b9"
android:layout_toRightOf="#+id/b0"
android:text="BACK" />
</RelativeLayout>
Use LinearLayout instead of RelativeLayout. And remove these in Buttons:
android:layout_alignParentLeft="true"
after that it should be fine.
EDIT: Not just left alignment directives, but all alignment directives.
i would suggest you to use TableLayout ... very easy to understand and fits what you want perfectly and its easy to reuse or modify later ... your code ...
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<EditText
android:id="#+id/orderQuantity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/b3"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="1" />
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="2" />
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="3" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="4" />
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="5" />
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="6" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="7"/>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="8"/>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="9" />
</TableRow>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="Add"/>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="0"/>
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:text="OK"/>
</TableRow>
</TableLayout>
Organize each row as below...
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/b4"
android:layout_alignParentLeft="true"
android:text="1" />
<Button
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/orderQuantity"
android:layout_toLeftOf="#+id/b3"
android:layout_toRightOf="#+id/b1"
android:text="2" />
<Button
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/b4"
android:layout_toRightOf="#+id/b2"
android:layout_centerHorizontal="true"
android:text="3" />
Ok after analyzing i was able to see whats wrong.
This
<Button
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/b4"
android:layout_centerHorizontal="true"
android:text="3" />
Should be :
<Button
android:id="#+id/b3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/b4"
android:text="3" />
I would do something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#595959">
<EditText
android:id="#+id/orderQuantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/b3"
android:background="#FFFFFF"
android:ems="10"
android:inputType="number"/>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/b1"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="1"/>
<Button
android:id="#+id/b2"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="2"/>
<Button
android:id="#+id/b3"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="3"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/b4"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="4"/>
<Button
android:id="#+id/b5"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="5"/>
<Button
android:id="#+id/b6"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="6"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/b7"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="7"/>
<Button
android:id="#+id/b8"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="8"/>
<Button
android:id="#+id/b9"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="9"/>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="#+id/b0"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="0"/>
<Button
android:id="#+id/addCart"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="ADD"/>
<Button
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_weight=".3333"
android:layout_height="match_parent"
android:text="BACK"/>
</LinearLayout>
</LinearLayout>

How to cut the screen?

I made my own simple calculator but I want to cut it, Can anyone help how do it?
Following is my pic where I want to cut this.
I used:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
But it's not working.pls help!
Here is my source code:
<LinearLayout 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:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#cccccc"
android:gravity="right"
android:padding="15dp"/>
<TableLayout
android:id="#+id/tableID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<TableRow>
<Button
android:id="#+id/btn7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7"/>
<Button
android:id="#+id/btn8"
android:text="8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/btn9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="9"
android:layout_weight="1"/>
<Button
android:id="#+id/btndiv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="÷"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<Button
android:id="#+id/btn4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="4"
android:layout_weight="1"/>
<Button
android:id="#+id/btn5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="5"
android:layout_weight="1"/>
<Button
android:id="#+id/btn6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="6"
android:layout_weight="1"/>
<Button
android:id="#+id/btnx"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="x"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="1"
android:layout_weight="1"/>
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="2"
android:layout_weight="1"/>
<Button
android:id="#+id/btn3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="3"
android:layout_weight="1"/>
<Button
android:id="#+id/btnsub"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="-"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<Button
android:id="#+id/btn0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="0"
android:layout_weight="1"/>
<Button
android:id="#+id/btnc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="C"
android:layout_weight="1"/>
<Button
android:id="#+id/btnequal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="="
android:layout_weight="1"/>
<Button
android:id="#+id/btnadd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="+"
android:layout_weight="1"/>
</TableRow>
</TableLayout>
</LinearLayout>
your main Linear Layout change like this change this line android:layout_height="wrap_content"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff00ff00"
android:orientation="vertical" >
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#cccccc"
android:gravity="right"
android:padding="15dp" />
<TableLayout
android:id="#+id/tableID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<TableRow>
<Button
android:id="#+id/btn7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7" />
<Button
android:id="#+id/btn8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="8" />
<Button
android:id="#+id/btn9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="9" />
<Button
android:id="#+id/btndiv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="÷" />
</TableRow>
<TableRow>
<Button
android:id="#+id/btn4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4" />
<Button
android:id="#+id/btn5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5" />
<Button
android:id="#+id/btn6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="6" />
<Button
android:id="#+id/btnx"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="x" />
</TableRow>
<TableRow>
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2" />
<Button
android:id="#+id/btn3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
<Button
android:id="#+id/btnsub"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
</TableRow>
<TableRow>
<Button
android:id="#+id/btn0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0" />
<Button
android:id="#+id/btnc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="C" />
<Button
android:id="#+id/btnequal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="=" />
<Button
android:id="#+id/btnadd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
</TableRow>
</TableLayout>
</LinearLayout>
android:theme="#android:style/Theme.DeviceDefault.Dialog.NoActionBar"
by adding this line to your manifest
<activity
android:name=".DemoActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.DeviceDefault.Dialog.NoActionBar" >
Or Try this in your xml:-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="30dp" >
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#cccccc"
android:gravity="right"
android:padding="15dp" />
<TableLayout
android:id="#+id/tableID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7" />
<Button
android:id="#+id/btn8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="8" />
<Button
android:id="#+id/btn9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="9" />
<Button
android:id="#+id/btndiv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="÷" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:id="#+id/btn4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4" />
<Button
android:id="#+id/btn5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5" />
<Button
android:id="#+id/btn6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="6" />
<Button
android:id="#+id/btnx"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="x" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:id="#+id/btn1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" />
<Button
android:id="#+id/btn2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2" />
<Button
android:id="#+id/btn3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" />
<Button
android:id="#+id/btnsub"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:id="#+id/btn0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0" />
<Button
android:id="#+id/btnc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="C" />
<Button
android:id="#+id/btnequal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="=" />
<Button
android:id="#+id/btnadd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+" />
</TableRow>
</TableLayout>

Android Linear Layout Suggestion

How do I get buttons to lay on the screen most optimally distributed and centered on the screen as follows:
The nearest I am able to get is this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="Button1" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button2" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button3" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Button5"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button6"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button7"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Button8"
android:layout_weight="1"/>
</LinearLayout>
Use a relativeLayout for the 3 linearLayouts.
To place the 3 linears below eachother use:
android:layout_below="#+id/linearLayout1"
and
android:layout_below="#+id/linearLayout2"
To center the linears use:
android:layout_centerInParent="true"
android:layout_gravity="center_vertical"
That will give you 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="horizontal" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_below="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button5" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button6" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button7" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_below="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button8" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button4" />
</LinearLayout>
Unfortunately it is not showing the last line which is </RelativeLayout>

Categories

Resources