How to use the Include file for Android programming _android

Source: Internet
Author: User

This example analyzes the use of the include file for Android programming. Share to everyone for your reference, specific as follows:

Remember a long time ago, listening to a great God said that programmers are lazy, not lazy programmers are not good programmers, then did not understand what the meaning. Then slowly understand the meaning of it, good programmers do not do repetitive work.

We are in the Android layout file, often encounter some of the same layout, each page is written, one is more trouble, and second, once there are changes have to change multiple files. We can use the include in this time.

Very simple to use, look at the code below

Files in include Scollandlisttitle.xml

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" Match_parent "android:layout_height=" wrap_content "android:orientation=" "Vertical" &
  Gt <linearlayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" Horizontal "android:background=" #000000 "> <textview android:id=" @+id/txt_left_f "Android:la Yout_width= "0DP" android:layout_height= "50DP" android:layout_weight= "1" android:gravity= "center" a ndroid:text= "literal" android:clickable= "true"/> <textview android:id= "@+id/txt_right_f" and
      Roid:layout_width= "0DP" android:layout_height= "50DP" android:layout_weight= "1" android:gravity= "center" android:text= "Picture" android:clickable= "true"/> </LinearLayout> <view android:id= "@+id" /view_line "Android:layOut_width= "50DP" android:layout_height= "1DP" android:background= "#FF0066"/> </LinearLayout>

 

And then look at the page that called it: Scollandlistviewpager.xml

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "Android:layout_width=" "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" a Ndroid:id= "@+id/vparent_layout" > <com.example.listsuspension.myscrollview android:id= "@+id/vscrollView" an Droid:layout_width= "Match_parent" android:layout_height= "Fill_parent" android:fillviewport= "true" > <Fram
        Elayout android:layout_width= "match_parent" android:layout_height= "wrap_content" > <linearlayout Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:orientation= "vertic"
          Al "> <imageview android:id=" @+id/viamge "android:layout_width=" Match_parent " android:layout_height= "Wrap_content" android:background= "@drawable/pic" android:scaletype= "cen ter "/> <Include android:id= "@+id/vtitle" layout= "@layout/scollandlisttitle"/> <androi D.support.v4.view.viewpager android:id= "@+id/viewpager" android:layout_width= "Match_parent" and roid:layout_height= "Fill_parent"/> </LinearLayout> <include android:id= "@+id/v" Top_title "layout=" @layout/scollandlisttitle "/> </FrameLayout> </com.example.listsu Spension.

 Myscrollview> </LinearLayout>

The above include code section is two references. Plus, you can see the contents of the include file displayed.

Here is a question, include the control ID is the same, this how to do it. It's very simple, they're contained in different include, so when you're using Findviewbyid, take it from include. Here is the code

Titlelayout = (linearlayout) Findviewbyid (r.id.vtitle);
Toptitlelayout = (linearlayout) Findviewbyid (r.id.vtop_title);
Viewpager = (Viewpager) Findviewbyid (R.id.viewpager);
Click the button event
Txt_left_fc = (TextView) Toptitlelayout.findviewbyid (r.id.txt_left_f);
Txt_left_fc.setonclicklistener (this);
Txt_right_fc = (TextView) Toptitlelayout.findviewbyid (r.id.txt_right_f);
Txt_right_fc.setonclicklist

I hope this article will help you with the Android program.

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.