Android Development Experience-fragment related

Source: Internet
Author: User

Dialogfragment

Issue background:

General app Development will encounter the need for pop-up windows, but dialogfragment default style is with the title bar, but this is often not needed, so we can set dialogfragment style

1 @Override 2  Public void onCreate (Bundle savedinstancestate) {3     Super . OnCreate (savedinstancestate); 4     SetStyle (dialogfragment.style_no_title, 0); 5 }

However, after this setting, you will find that the height and width of the dialog is not what you want, how you set the height and width of the root view is useless, when the Android system ignores the height and width of the root view,

So I take a trickery approach is that the root view is set to Relativelayout or Framelayout, then the first view is space or view, this view is set to the width and height you want, as follows

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent" >5 6     <Space7         Android:layout_width= "Wrap_content"8 Android:layout_height= "Wrap_content"9 Android:minheight= "248.5DP"Ten Android:minwidth= "250DP" /> One  A     <LinearLayout -         Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the android:gravity= "Center" - android:orientation= "vertical" - Android:paddingbottom= "39DP" - Android:paddingleft= "20DP" + Android:paddingright= "20DP" - Android:paddingtop= "30DP" > +  A     </LinearLayout> at  - </Relativelayout>

Issue background:

Sometimes we need to use nested fragment, but the use of nested fragment has a limitation, that is, only through the dynamic addition of code, not by adding in the XML, the official website explains,

Note: You cannot inflate a layout to a fragment when that layout includes a <fragment> . Nested fragments is only supported if added to a fragment dynamically.

So the question is, if fragment's container view is linearlayout, what if I set the margin between the fragment?

Solution:

My method is to set the margin of the view in the OnStart or Onresume method of the child fragment, but it is necessary to judge that the current fragment is the number of children of container.

Android Development Experience-fragment related

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.