Take a look at some of the tips you'll find useful in the 50 tips that Android developers must know about.
Include label usage considerations
If you want to overwrite any of the android:layout_* properties specified by the included layout in the label, you must specify both the Android:layout_width and Android:layout_height properties in the label. We can do this by specifying that the Layout_width and Layout_height properties of the included layout are all 0DP, so that the consumer of the included layout specifies the Layout_width and Layout_height attributes in the label. If the consumer does not specify these two properties, their default value is 0, and we will not see it.
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 get a reference to the filled view, the inflate () method returns the reference directly, avoiding the call to the Findviewbyid () method again
Custom Layouts Get custom properties
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(...));
Get the width and height of the view in OnCreate
Calling GetWidth () and GetHeight () in OnCreate will return 0, and the width and height can be obtained through the view's post method.
Remove log statements when publishing
Add the following statement into the obfuscation file to remove the confusion
-assumenosideeffects class android.util.Log { public static *** d(...);}
Using delegates
The implementation of the operation in the adapter is not implemented in the adapter, the adapter provides an interface, delete the operation call interface corresponding method, its implementation by the activity implementation.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"50 Tips for Android development" Reading notes