android - RelativeLayout does not expand with the heights of view elements -
i have relative layout set wrap_content
in height. has 2 textview , 2 edittext. however, relativelayout not match height of edittexts.
dashed rectangle region highlighted android studio preview tool borders of relativelayout.
the actual problem when run app bottom edittext kind of goes below relative layout , bottom part disappears. thereby, user can't see bottom line , don't know there textfield.
android studio preview:
problem , result on emulator:
xml file:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="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"> <android.support.v4.widget.space android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="5" /> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/numberofdaystextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:text="@string/initialnumberofdays" android:textappearance="?android:attr/textappearancelarge" android:textsize="58sp" /> <textview android:id="@+id/daystext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/numberofdaystextview" android:layout_centerhorizontal="true" android:layout_margintop="10dp" android:text="@string/daystext" android:textappearance="?android:attr/textappearancelarge" android:textsize="15sp" /> </relativelayout> <android.support.v4.widget.space android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="3" /> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/fromdatepickertextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:text="@string/fromtextview" android:textsize="15sp" /> <edittext android:id="@+id/fromdate" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/fromdatepickertextview" android:layout_marginleft="28dp" android:layout_marginstart="28dp" android:layout_toendof="@+id/fromdatepickertextview" android:layout_torightof="@+id/fromdatepickertextview" android:ems="10" android:focusableintouchmode="false" android:inputtype="date" /> <textview android:id="@+id/todatepickertextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignend="@+id/fromdatepickertextview" android:layout_alignright="@+id/fromdatepickertextview" android:layout_below="@+id/fromdatepickertextview" android:layout_margintop="32dp" android:text="@string/totextview" android:textsize="15sp" /> <edittext android:id="@+id/todate" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/todatepickertextview" android:layout_marginleft="28dp" android:layout_marginstart="28dp" android:layout_margintop="22dp" android:layout_toendof="@+id/todatepickertextview" android:layout_torightof="@+id/todatepickertextview" android:ems="10" android:focusableintouchmode="false" android:inputtype="date" /> </relativelayout> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <button android:id="@+id/calculatedaysbutton" android:layout_width="160dp" android:layout_height="40dp" android:layout_centerhorizontal="true" android:layout_marginbottom="15dp" android:layout_margintop="40dp" android:background="@drawable/button_bg" android:text="@string/calculatebuttontext" android:textcolor="@android:color/white" /> </relativelayout> </linearlayout>
edit: another solution has worked:
textview must aligned baseline of edittext , not reverse way!
<relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/fromdatepickertextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_alignbaseline="@+id/fromdate" android:text="@string/fromtextview" android:textsize="15sp" /> <edittext android:id="@+id/fromdate" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_marginleft="28dp" android:layout_marginstart="28dp" android:layout_toendof="@+id/fromdatepickertextview" android:layout_torightof="@+id/fromdatepickertextview" android:ems="10" android:focusableintouchmode="false" android:inputtype="date" /> <textview android:id="@+id/todatepickertextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignend="@+id/fromdatepickertextview" android:layout_alignright="@+id/fromdatepickertextview" android:layout_alignbaseline="@+id/todate" android:layout_margintop="32dp" android:text="@string/totextview" android:textsize="15sp" /> <edittext android:id="@+id/todate" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_marginleft="28dp" android:layout_marginstart="28dp" android:layout_margintop="10dp" android:layout_toendof="@+id/todatepickertextview" android:layout_torightof="@+id/todatepickertextview" android:layout_below="@+id/fromdate" android:ems="10" android:focusableintouchmode="false" android:inputtype="date" /> </relativelayout>
you should use
linear layout
instead ofrelative layout
.check out below code have done modification , applied
linear layout
. can modifymargin
,height
,width
.
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="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"> <android.support.v4.widget.space android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="5" /> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/numberofdaystextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:text="0" android:textappearance="?android:attr/textappearancelarge" android:textsize="58sp" /> <textview android:id="@+id/daystext" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/numberofdaystextview" android:layout_centerhorizontal="true" android:layout_margintop="10dp" android:text="day" android:textappearance="?android:attr/textappearancelarge" android:textsize="15sp" /> </relativelayout> <android.support.v4.widget.space android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="3" /> <linearlayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/fromdatepickertextview" android:layout_width="30dp" android:layout_height="wrap_content" android:text="to" android:textsize="15sp" /> <edittext android:id="@+id/fromdate" android:layout_width="130dp" android:layout_height="45dp" android:layout_marginleft="28dp" android:layout_marginstart="28dp" android:ems="10" android:focusableintouchmode="false" android:inputtype="date" /> </linearlayout> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/todatepickertextview" android:layout_width="30dp" android:layout_height="wrap_content" android:layout_margintop="32dp" android:text="feom" android:textsize="15sp" /> <edittext android:id="@+id/todate" android:layout_width="130dp" android:layout_height="wrap_content" android:layout_marginleft="28dp" android:layout_marginstart="28dp" android:layout_margintop="22dp" android:ems="10" android:focusableintouchmode="false" android:inputtype="date" /> </linearlayout> </linearlayout> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <button android:id="@+id/calculatedaysbutton" android:layout_width="160dp" android:layout_height="40dp" android:layout_centerhorizontal="true" android:layout_marginbottom="15dp" android:layout_margintop="40dp" android:background="@drawable/button_bg" android:text="@string/calculatebuttontext" android:textcolor="@android:color/white" /> </relativelayout> </linearlayout>
hope solves problem.
Comments
Post a Comment