Android Java - Some of the Buttons have Text Aligned to the Right -
some of buttons
(2, 4, 6, 8, 0, -, , /) have text aligned right
instead of left
. strange thing have textalignment
properties of buttons not have center text set center
. here main_activity.xml
. sorry if it's simple mistake, still learning android app development.
<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" android:background="#ffffffff" android:id="@+id/relativelayout"> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button2" android:text="/" android:background="#ff6600" android:onclick="appendcharacter" android:layout_alignparentbottom="true" android:layout_torightof="@+id/button4" android:layout_toendof="@+id/button4" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button4" android:text="*" android:background="#ff6600" android:onclick="appendcharacter" android:layout_aligntop="@+id/button5" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button5" android:text="=" android:background="#85c2ff" android:layout_alignparentbottom="true" android:layout_alignparentright="true" android:layout_alignparentend="true" android:onclick="displayresult" android:layout_alignleft="@+id/button19" android:layout_alignstart="@+id/button19" android:layout_toendof="@+id/button2" android:layout_torightof="@+id/button2" /> <textview android:layout_width="0dp" android:layout_height="0dp" android:id="@+id/textview" android:layout_below="@+id/button2" android:layout_alignright="@+id/button" android:layout_alignend="@+id/button" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" android:text="+" android:background="#ff6600" android:layout_above="@+id/button2" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:onclick="appendcharacter" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button3" android:text="-" android:background="#ff6600" android:layout_below="@+id/button6" android:layout_torightof="@+id/button" android:layout_toendof="@+id/button" android:onclick="appendcharacter" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button6" android:text="0" android:background="#ffff5830" android:layout_above="@+id/button" android:layout_torightof="@+id/button7" android:layout_toendof="@+id/button19" android:onclick="appendcharacter" android:textalignment="center" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button7" android:text="9" android:background="#ffff5830" android:layout_alignbottom="@+id/button6" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:onclick="appendcharacter" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button8" android:text="8" android:background="#ffff5830" android:layout_above="@+id/button6" android:layout_torightof="@+id/button7" android:layout_toendof="@+id/button7" android:onclick="appendcharacter" android:textalignment="center" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button9" android:text="7" android:background="#ffff5830" android:layout_above="@+id/button7" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:onclick="appendcharacter" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button10" android:text="6" android:background="#ffff5830" android:onclick="appendcharacter" android:layout_below="@+id/button13" android:layout_torightof="@+id/textview" android:layout_toendof="@+id/textview" android:textalignment="center" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button11" android:text="5" android:background="#ffff5830" android:layout_above="@+id/button9" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:onclick="appendcharacter" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button12" android:text="4" android:background="#ffff5830" android:onclick="appendcharacter" android:layout_above="@+id/button10" android:layout_torightof="@+id/button11" android:layout_toendof="@+id/button11" android:textalignment="center" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button13" android:text="3" android:background="#ffff5830" android:onclick="appendcharacter" android:layout_above="@+id/button11" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button14" android:text="2" android:background="#ffff5830" android:layout_above="@+id/button12" android:layout_torightof="@+id/button13" android:layout_toendof="@+id/button13" android:onclick="appendcharacter" android:textalignment="center" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button15" android:text="1" android:background="#ffff5830" android:layout_alignbottom="@+id/button14" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:onclick="appendcharacter" android:textalignment="center" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button17" android:text=")" android:background="#ff6600" android:onclick="appendcharacter" android:layout_above="@+id/button5" android:layout_alignright="@+id/edittext2" android:layout_alignend="@+id/edittext2" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button18" android:text="cot" android:background="#ff6600" android:layout_below="@+id/button8" android:layout_alignparentright="true" android:layout_alignparentend="true" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button19" android:text="tan" android:background="#ff6600" android:layout_aligntop="@+id/button18" android:layout_toleftof="@+id/button17" android:layout_tostartof="@+id/button17" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button20" android:text="sec" android:background="#ff6600" android:layout_above="@+id/button18" android:layout_alignparentright="true" android:layout_alignparentend="true" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button21" android:text="cos" android:background="#ff6600" android:layout_aligntop="@+id/button20" android:layout_toleftof="@+id/button18" android:layout_tostartof="@+id/button18" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button22" android:text="csc" android:background="#ff6600" android:layout_alignbottom="@+id/button10" android:layout_alignparentright="true" android:layout_alignparentend="true" android:onclick="appendcharacter" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button23" android:text="sin" android:background="#ff6600" android:onclick="appendcharacter" android:layout_below="@+id/button24" android:layout_alignleft="@+id/button19" android:layout_alignstart="@+id/button19" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button24" android:text="equation" android:background="#ffffcf23" android:layout_below="@+id/button26" android:layout_alignparentright="true" android:layout_alignparentend="true" android:layout_alignleft="@+id/button26" android:layout_alignstart="@+id/button26" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button25" android:text="units" android:background="#ffffcf23" android:layout_above="@+id/button14" android:layout_alignparentright="true" android:layout_alignparentend="true" android:layout_toendof="@+id/button27" android:layout_torightof="@+id/button27" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button26" android:text="matrix" android:background="#ffffcf23" android:layout_above="@+id/button12" android:layout_alignparentright="true" android:layout_alignparentend="true" android:layout_torightof="@+id/button27" android:layout_toendof="@+id/button27" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button27" android:text="settings" android:background="#ff33ff8e" android:layout_above="@+id/button14" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_tostartof="@+id/button23" android:layout_toleftof="@+id/button23" /> <edittext android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/edittext2" android:layout_above="@+id/button27" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_alignparentright="true" android:layout_alignparentend="true" android:textcolor="#000000" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button16" android:text="(" android:background="#ff6600" android:onclick="appendcharacter" android:layout_aligntop="@+id/button3" android:layout_alignright="@+id/button19" android:layout_alignend="@+id/button19" /> </relativelayout>
all buttons appear have centered text when have enough space:
but buttons on right side might overlap part of left side buttons if don't have enough space. happens because specify positions left right left "column" , right left right "column". when sum of wrapped widths higher device width, overlap occurs.
in order avoid kind of issues, recommend use type of layout https://developer.android.com/guide/topics/ui/layout/grid.html using weight attribute in order make responsive.
also, current implementation, if device wide, you'll have white space between columns (a table layout fix this).
you might want check other question: linear layout calculator app
Comments
Post a Comment