android - Custom view is measured incorrectly when placed with another view elements -
i created custom view want place in relativelayout button under it. problem i'm having if put button under custom view using android:layout_below="@id/customview", customview takes full height, there's no space on screen place button, it's placed below bottom border of screen , therefore invisible. size receive @ last call of customview's onmeasure() method should calculated, i.e. view sizes should taken account, seems in case height of button not.
here's layout:
<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:background="@color/darkbluebackground" tools:context="com.example.timepickeractivity"> <com.example.timepicker android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="5dp" android:paddingright="20dp" android:paddingtop="5dp" android:paddingbottom="5dp" android:id="@+id/picker"/> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/picker" android:layout_weight="1" android:id="@+id/okbutton" android:text="ok"/>
this final sizes measured onmeasure():
07-26 00:24:39.551 19930-19930/com.example d/tag: width = 720 height = 1230
at same time if put button above customview looks pretty fine, onmeasure() receives correct height customview, there's space button.
here's layout case:
<button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/okbutton" android:text="ok"/> <com.example.timepicker android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/okbutton" android:paddingleft="5dp" android:paddingright="20dp" android:paddingtop="5dp" android:paddingbottom="5dp" android:id="@+id/picker"/>
final size onmeasure different: 07-26 00:24:39.551 19930-19930/com.example d/tag: width = 720 height = 1134
why custom view (timepicker) measured correctly in 1 case , isn't in another?
try setting android:layout_height=wrap_content"
on com.example.timepicker
view. setting height match_parent
causes view fill parent's height, leaving no room button.
Comments
Post a Comment