android - Horizontal scroll view expanding when views added programmatically -
i'm having problems when adding views programmatically horizontal scroll view. have horizontal scroll view dotted background , have given linear layouts around clear colour backgrounds aid understanding.
this view looks prior
then add together view scroll view after drag , drop event:
memonodeview mn = new memonodeview(this); mn.setmemo(m); int time = (int) math.round(pixelspermillisecond()*m.gettimelength()); mn.setmemosize(time, timelineheight); timeline.addview(mn, new viewgroup.marginlayoutparams(time, timelineheight)); this leads view expanding in size vertically:
i attempted prepare re-setting layout params of linear layout within scroll view based on height supposed have:
viewgroup.layoutparams p = timeline.getlayoutparams(); p.height = timelineheight; timeline.setlayoutparams(p); leading situation scroll view still expanded content right size:
i tried resize scroll view size matched supposed to:
viewgroup.layoutparams p2 = timelinescrollview.getlayoutparams(); p2.height = timelineheight; timelinescrollview.setlayoutparams(p2); which gave:
leaving size of scroll view correct, size of other views shrunken , in wrong position. want scroll view remain same in first image , nil move around. may basic, cant life of me figure out i'm doing wrong give behaviour.
the xml area follows (note colours/ text views placeholders used seek , help create issue stand out visually):
`<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/black_frame" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#ffffff" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="small text" /> </linearlayout> <linearlayout android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="3" android:orientation="vertical" android:paddingleft="@dimen/toggle_draw_padding" android:paddingright="@dimen/toggle_draw_padding" > <horizontalscrollview android:id="@+id/horizontal_scroll_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/timeline_dots_bitmap" android:fillviewport="true"> <linearlayout android:id="@+id/timeline_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="horizontal" android:background="#f0aa4444" > </linearlayout> </horizontalscrollview> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:background="#ffffff" > <textview android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="small text" /> </linearlayout> </linearlayout>` any ideas doing wrong here?
i found out causing issue. i'll post here in case else has similar issue , driving them mental...
the linear layouts had white backgrounds had layout_height="match_parent" gave weird behaviour when other views added. changing 2 layouts layout_height="0dip" solves issue. shown below:
`
<linearlayout android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" android:background="#ffffff" > <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="small text" /> </linearlayout> <linearlayout android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="3" android:orientation="vertical" android:paddingleft="@dimen/toggle_draw_padding" android:paddingright="@dimen/toggle_draw_padding" > <horizontalscrollview android:id="@+id/horizontal_scroll_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/timeline_dots_bitmap" android:fillviewport="true" android:layout_margin="0dip" android:padding="0dip"> <linearlayout android:id="@+id/timeline_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="horizontal" android:background="#f0aa4444" android:layout_margin="0dip" android:padding="0dip"> </linearlayout> </horizontalscrollview> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="0dip" android:layout_weight="1" android:background="#ffffff" > <textview android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="small text" /> </linearlayout> </linearlayout>` i hope can help somehow makes same error did.
android android-linearlayout android-custom-view horizontalscrollview
No comments:
Post a Comment