Android.support.v4.app.Fragment and Android.app.Fragment differences

Source: Internet
Author: User

Today in the company encountered a android.app.Fragment and android.support.v4.app.Fragment problem.

(1) Android.app.Fragment: The minimum compatible version is android:minsdkversion= "11" so your app is not compatible with apps under 3.0.

can use the <fragment> label, this is very important, if the use of android.support.v4.app.Fragment words, is not to use the <fragment> tag, Will throw android.view.InflateException:Binary XML file line #7: Error inflating class fragment exception

(2) Android.support.v4.app.Fragment: can be compatible to 1.6 version, cannot use <fragment> tag, need to be added in the program by add or replace, but also need

Android-support-v4.jar

Two fragment manager get noticed differently

The first android.app.Fragment layout ----Manager Getfragmentmanager//Get manager

<fragment        android:id= "@+id/fragment1"        android:layout_width= "wrap_content"        android:layout_height = "Wrap_content"/>

The second android.support.v4.app.Fragment way the main activity must inherit fragmentactivity---------Manager getsupportfragm Entmanager get the manager

Note the imported package

The first way of layout

<fragment        android:id= "@+id/fragment1"        <span style= "color: #ff0000;" ><strong>android:name= "Com.text.fragment" </strong></span>        android:layout_width= "Wrap_ Content "        android:layout_height=" Wrap_content "/>

Notice that the name above is the path address of your child fragment.

The second way of layout

    <framelayout        android:id= "@+id/fragment1"        android:layout_width= "wrap_content"        android:layout_ height= "Wrap_content"/>


Both types cannot be mixed using special attention. Hope to be helpful.






Android.support.v4.app.Fragment and Android.app.Fragment differences

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.