java - Cannot create two TextView in two lines -


this rather layman question totally green in android development.

recently trying implement simple calculator using android.

i want make 2 rows of calculator display, top 1 showing equations user has input, , bottom 1 answer.

here code in layout xml file:

<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=".mainactivity" >  <linearlayout     android:id="@+id/linearlayout0"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_alignparentleft="true">      <textview         android:id="@+id/calculatordisplay0"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:gravity="right"         android:maxlines="1"         android:paddingleft="10dp"         android:paddingright="10dp"         android:textappearance="?android:attr/textappearancelarge"         android:textsize="40sp" /> </linearlayout>  <linearlayout     android:id="@+id/linearlayout1"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"      android:layout_below="@+id/linearlayout0" >      <textview         android:id="@+id/calculatordisplay1"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:gravity="right"         android:layout_below="@id/calculatordisplay0"         android:maxlines="1"         android:paddingleft="10dp"         android:paddingright="10dp"         android:text="0"         android:textappearance="?android:attr/textappearancelarge"         android:textsize="40sp" /> </linearlayout>      .      .      .      . 

however, result:

enter image description here

as can see, 2 lines nested together.

i pretty sure wrong code, cannot locate it. me on it?

android:layout_alignparentleft="true" android:layout_alignparenttop="true" 

those attributes in second linearlayout have explicitly declared want second textview (content of linearlayout) overlap @ top. i'm not sure think same without specifying layout_* attributes in linearlayout. on second seams android:layout_below="@+id/linearlayout0" attribute ignored. in case, in conflict layout_alignparenttop, watch out in future.

the desired behavior have described typical linearlayout android:orientation="vertical" attribute. on right track. have change move second textview in first linearlayout, can see has 2 views manage , add desired orientation attribute because default orientation horizontal [1].

layout 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=".mainactivity" >  <linearlayout     android:id="@+id/linearlayout0"     android:layout_width="match_parent"     android:layout_height="wrap_content">      <textview         android:id="@+id/calculatordisplay0"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:gravity="right"         android:maxlines="1"         android:paddingleft="10dp"         android:paddingright="10dp"         android:textappearance="?android:attr/textappearancelarge"         android:textsize="40sp" />      <textview         android:id="@+id/calculatordisplay1"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:gravity="right"         android:layout_below="@id/calculatordisplay0"         android:maxlines="1"         android:paddingleft="10dp"         android:paddingright="10dp"         android:text="0"         android:textappearance="?android:attr/textappearancelarge"         android:textsize="40sp" />  </linearlayout>      .      .      .      . 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -