Code Monkey home page Code Monkey logo

reskin1's People

Contributors

fengshenzhu avatar

Stargazers

 avatar

Watchers

 avatar

reskin1's Issues

xml布局中View加style属性都会报错

无论是系统style还是自定义style,都会报错:

java.lang.NumberFormatException: Invalid int: "xxxxxx"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:410)
at java.lang.Integer.parseInt(Integer.java:367)
at java.lang.Integer.parseInt(Integer.java:334)
at skin.lib.SkinLayoutInflaterFactory.addSkinViewIfNecessary(SkinLayoutInflaterFactory.java:153)
at skin.lib.SkinLayoutInflaterFactory.onCreateView(SkinLayoutInflaterFactory.java:108)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
... 46 more

系统:

java.lang.NumberFormatException: Invalid int: "android:style/Widget.ProgressBar.Large"

自定义:

java.lang.NumberFormatException: Invalid int: "style="@style/roomRatingBar"

动态Fragment是否需要添加View列表管理?

现在所有属于一个Activity的View都会添加到一份列表里,自定义View可以通过onAttachedToWindow()``onDetachedFromWindow()添加/移除,Fragment是否也需要通过onAttach()``onDetach()做次操作?

各种获取LayoutInflater方式的风险

获取LayoutInflater的方式:

1. Context
1.1 LayoutInflater.from(activity)
1.2 LayoutInflater.from(activity.getApplicationContext())
1.3 LayoutInflater.from(activity.getBaseContext())
2. Activity
2.1 Activity.getLayoutInflater()
3. Fragment
3.1 Fragment.getLayoutInflater(savedInstanceState)
3.2 Fragment.onCreateView(LayoutInflater inflater, ...)
4. View
4.1 View.inflater(context...)

其中,只有1.1和2.1获取的是同一个LayoutInflater对象,其它都不是同一个对象。
Fragment3.1和3.2LayoutInflater对象的Factory是Merge之后的,其中一个对象与1.1的Factory相同。(更详细见LayoutInflater.FactoryMerge)

activity布局xml中有fragment报错

Caused by: android.view.InflateException: Binary XML file line #8: Class is not a View android.support.v4.app.Fragment
                                                               at android.view.LayoutInflater.createView(LayoutInflater.java:636)
                                                               at skin.lib.SkinLayoutInflaterFactory.createView(SkinLayoutInflaterFactory.java:132)
                                                               at skin.lib.SkinLayoutInflaterFactory.onCreateView(SkinLayoutInflaterFactory.java:94)

Activity中动态添加Fragment出错

Fragment onCreateView()使用参数中inflater布局

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_a, container, false);
}

布局fragment xml时报错:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
                                                       at android.view.ViewConfiguration.get(ViewConfiguration.java:364)
                                                       at android.view.View.<init>(View.java:3794)
                                                       at android.view.View.<init>(View.java:3898)
                                                       at android.view.ViewGroup.<init>(ViewGroup.java:573)
                                                       at android.widget.LinearLayout.<init>(LinearLayout.java:203)
                                                       at android.widget.LinearLayout.<init>(LinearLayout.java:199)
                                                       at android.widget.LinearLayout.<init>(LinearLayout.java:195)
                                                       at java.lang.reflect.Constructor.newInstance(Native Method) 
                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:619) 
                                                       at skin.lib.SkinLayoutInflaterFactory.createView(SkinLayoutInflaterFactory.java:126) 
                                                       at skin.lib.SkinLayoutInflaterFactory.onCreateView(SkinLayoutInflaterFactory.java:99) 
                                                       at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:190) 
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746) 
                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
                                                       at skin.demo.FragmentA.onCreateView(FragmentA.java:31) 

使用getActivity().getLayoutInflater()不会出错。

自定义View优化

自定义View的attach和detach操作可通过View#addOnAttachStateChangeListener()简化成一步。xml里由库添加lisenter,手动new View后需手动添加lisenter

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.