50 tips required for Android development: Reading Notes and Android Reading Notes
Record the tips that I think are useful when I read "50 tips required for Android development.
Considerations for using include labels
If you want to overwrite any android: layout _ * attribute specified by the contained layout in the tag, you must specify both android: layout_width and android: layout_height attributes in the tag, you can specify that the layout_width and layout_height attributes of the layout to be included are 0dp. In this way, the owner of the layout can specify the layout_width and layout_height attributes in the tag, if you do not specify these two attributes, their default values are 0, and we will not see them.
ViewStub label
<ViewStub> android:id="@+id/view_stub" android:inflateId="@+id/inflateId"</ViewStub>View view=findViewById(R.id.view_stub)view.setVisibility(View.VISIBLE);
If you want to obtain the reference of the filled view, the inflate () method will return the reference directly. You can avoid calling the findViewById () method again.
Custom layout to get Custom Attributes
You can release TypeArray in finally.
TypeArray a=context.obtainStyledAttribute(attrs,R.styleable.Custom);try{}finally{ a.recycle();}
SpannableString
Spannable spannable=new SpannableString("");spannable.setSpan(new BackgroundColorSpan(...));
Obtain the width and height of the View in onCreate.
Call getWidth () and getHeight () in onCreate to return 0. You can use the post method of View to obtain the width and height.
Remove log statements when publishing
Add the following statement to the obfuscation file to remove it.
-assumenosideeffects class android.util.Log { public static *** d(...);}
Use Delegation
The implementation of operations such as deleting in the adapter is not implemented in the adapter. The adapter provides an interface. The method corresponding to the interface called by the delete operation is implemented by the Activity.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.