Android uses Horizontalscrollview to achieve title drive content left and right cutting screen

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.