Android uses Horizontalscrollview to achieve title drive content left and right cutting screen
Add <HorizontalScrollView> tags to the layout,
<Relativelayoutxmlns: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"Tools:context=". Mainactivity " > <HorizontalscrollviewAndroid:id= "@+id/horizontalscrollview1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true" > </Horizontalscrollview> </Relativelayout>
Note: Here you add a linearlayout layout directly to the Horizontalscrollview in the layout,
a child layout appears with a parent layout, to first use Removevie () to exclude a parent-child relationship, however, there is no implementation,
Finally, use new to get LinearLayout, and add sub-view without centering to LinearLayout
Final LinearLayout layout = new LinearLayout (this);
Logic code, by adding a horizontalscrollview to the
A linearlayout that adds a child view to the LinearLayout
Public classMainactivityextendsActivity {PrivateHorizontalscrollview HSV; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); HSV=(Horizontalscrollview) Findviewbyid (R.ID.HORIZONTALSCROLLVIEW1); Initview (); } Public voidInitview () {string[] mtexts= { "Focus", "domestic", "foreign", "military", "Focus", "domestic", "foreign", "military", "more" }; Final LinearLayout layout = new LinearLayout (this);
Add Child view
for(inti = 0; i < mtexts.length; i++) {Button btn=NewButton ( This); Btn.setid (i); Btn.settext (Mtexts[i]); Layout.addview (BTN); } hsv.addview (layout); }}
Android uses Horizontalscrollview to achieve title drive content left and right cutting screen
Android uses Horizontalscrollview to achieve title drive content left and right cutting screen