In Android, setlayoutparams must use the layoutparams of the parent control.

Source: Internet
Author: User

These daysProgramIf you want to understand a problem, record it here.

Actionbarcustomview customview = new actionbarcustomview (context );
Actionbar. layoutparams Lp = new actionbar. layoutparams (
Layoutparams. match_parent, layoutparams. match_parent,
Gravity. center_vertical );
Customview. setlayoutparams (LP );

Add a sub-View to the actionbar. actionbarcustomview is a sub-view written by you.

WhereIf the parent control is actionbar, it must be written as actionbar. layoutparams.

If the parent control is linearlayout, it must be written as linearlayout. layoutparams.

Linearlayout. layoutparams = new linearlayout. layoutparams (
Layoutparams. match_parent, layoutparams. match_parent );
Layoutparams. Gravity = gravity. Center;

The child view layout should be based on the parent control. If your child layout is displayed by the parent layout, you must set it like this, otherwise, the Child view is incorrectly displayed in the parent view.

Generally, this problem will not be exposed. It will only appear when you use details.

 

Related Article

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.