"50 Tips for Android development" Reading notes

Source: Internet
Author: User

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

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.