Android GridView several important attributes

Source: Internet
Author: User

First, Android:scrollbarstyle determine the position of the status bar     Common Properties Outsideoverlay, scroll bar at outermost, GridView set padding inside scroll bar Second, Android:stretchmode decide how to allocate the remaining space SpacingwidthRemove the left and right padding of GridItem and GridView, the remaining space totalspace with the free space in the middle to expand, here the total number of divided space n = columns-1, this n space divided Totalspace SpacingwidthuniformRemove the left and right padding of GridItem and GridView, the remaining space totalspace with n= columns + 1 spaces to divide. The difference with spacingwidth is that the partition space is more than two, that is, there is one on the left and right side of the GridView, and does not include padding. ColumnWidthRemoving the left and right padding and horizontalspacing of the GridView, filling the remaining space with the width of the column, is to divide the remaining space evenly to the width of each column. three, Android:listselector set each item of the pressed effect, this property a bit pit, the specific explanation as followsMany times we will customize the layout of each item of the GridView, click the effect will also use their own, do not use the system. Under normal circumstances, if the custom item is smaller than the item within each GridView, then we will respond to the effect of the system when we press the GridView item, but if our custom item is as large as the GridView item and the Click event is set , this time will not point the system of the effect of the press. Then the problem came, there was no visual problem, but we found that the GridView on both sides of a number of padding (here even if the GridView padding, this padding will accumulate),    Originally found that the system default Listselctor comes with a padding, this padding will be added to the GridView padding up. To solve the problem above, set up a listselector to replace the system. Next look at how this listselector affect the padding. 1. System method abslistview A variable is set in the setselector of the mselectionrightpaddingpublic void Setselector (drawable sel) {
if (mselector! = null) {
Mselector.setcallback (NULL);
Unscheduledrawable (Mselector);
}
Mselector = sel;
Rect padding = new rect ();
Sel.getpadding (padding);
mselectionleftpadding = padding.left;
mselectiontoppadding = padding.top;
mselectionrightpadding = padding.right;
mselectionbottompadding = Padding.bottom;
Sel.setcallback (this);
Updateselectorstate ();
} 2. Abslistview Onmeasure changed the value of mlistpading, here is really fuck, make a temporary variable to change the value, do not understand that. @Override
protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {
if (Mselector = = null) {
Usedefaultselector ();
}
final Rect listpadding = mlistpadding;
listpadding.left = mselectionleftpadding + mpaddingleft;
listpadding.top = mselectiontoppadding + mpaddingtop;
listpadding.right = mselectionrightpadding + mpaddingright;
Listpadding.bottom = mselectionbottompadding + mpaddingbottom;Omit other code} 3. In the Makerow method of the GridView, the mlistpading is accumulated .  Private View makerow (int startpos, int y, Boolean flow) {
Final int columnWidth = Mcolumnwidth;
Final int horizontalspacing = mhorizontalspacing;

Final Boolean Islayoutrtl = Islayoutrtl ();

int last;
int nextleft;

if (ISLAYOUTRTL) {
Nextleft = GetWidth ()-Mlistpadding.right-columnwidth-
((Mstretchmode = = stretch_spacing_uniform)? horizontalspacing:0);
} else {
nextleft = mlistpadding.left +
((Mstretchmode = = stretch_spacing_uniform)? horizontalspacing:0);
}//This adds up here, by the way you can see Spacingwidthuniform Familiar Role

if (!mstackfrombottom) {
Last = math.min (startpos + mnumcolumns, mitemcount);
} else {
Last = startpos + 1;
startpos = Math.max (0, startpos-mnumcolumns + 1);

if (Last-startpos < Mnumcolumns) {
Final int deltaleft = (Mnumcolumns-(Last-startpos)) * (ColumnWidth + Horizontal Spacing);
Nextleft + = (islayoutrtl?-1: + 1) * DELTALEFT;
}
}//Omit other code}

Android GridView several important attributes

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.