TListView 的 Header 部分默认 BtnFace 颜色,高度也不能改变。我们可以通过编写一些代码来实现这些功能;

  • 获得TListView 的Header 的句柄;

    TListView的Header其实是一个 HeaderContorl 控件。要获得他的句柄需要调用下面的代码

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------- static HWND hListViewHeader = NULL; __fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender)
{
//获得ListView Header的句柄
hListViewHeader = ListView_GetHeader(ListView1->Handle);
}
//---------------------------------------------------------------------------

其实还有许多ListView_XXXX 这样的windows API ,需要查看MSDN;

  • 改变Header的高度

Header的高度,是在一个处理一个叫 HDM_LAYOUT 的消息的时候进行设置。

msdn的原话如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAusAAACoCAIAAADWyDeBAAAgAElEQVR4nO2d7W9c1Z3H5w/ghaX8A9Zq0UqLtLK6bUmrxXLSktSpqQbUpFiRqNtaSZEarxvUPDRCY0qXIvIwymJBYkQsKwui3caGGko6kM5610FhiTOp0mIevIwhMsRixYTWWajy4u6LMz4+c8/DPXeePNf+fHQVjc+c8zu/c+6593xzniYVBMErr7wSAAAAACSHVICCAQAAgKSBggEAAIDkgYIBAACA5IGCAQAAgOSBggEAAIDkgYIBAACA5IGCAQAAgOSBggEAAIDkgYIBAACA5IGCAQAAgOSBggEAAIDkgYIBAACo4MafPzs/UXhq768O3ze2q+Nnuzp+dnDTkcP3jZ1+cPL8RCEyeSaTKRaL4nOxWBwdHS2VSoODg1X7Mzg42NXVVXXytQoKBgAAoMy1jz49/eCkUC07O4bK1989qF57vvLIL4+eu/Hnz2xGUqlUX1+f+NzX1yfEx8TERNVetbe3B0GQzWbz+bywWYseWjOgYAAAAIIbf/7sl0fPSeHy7S88/O0vPLz17w+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VPclug56Nhc97zmXIk92m0npZtGfnbdPfi/sMwVdiJNTXjjmyzL8dgPMtry6sWBSO/Mj6DRgu2EM+2Vx21KhifaD4WbK8n9XONrw9Hwqqr2/OxrJdLbj8j66eKunI37siM4gZ6vqbd3lbhko81h6k6dhXuCHEzqrFv9snFeOOqqFibP5H9qNu9yJhumz7Z+bvk/8K0Pd2et8P9uYrkVRu0xa/xVenfi+tJqlMDxqxj+enjT9BKCsb9otMt2EKSoWB8XrJ16fPcXlXXPzVNwVThkr+fNd4Ot1eRgqlGBWPMSO9dfFytwqVIa9WVqO42m6Zg4pbIoWAaEVi1nzabnk9ZXAVTRfK4gY449VIwTWuK/jabOXNUrzGYWpRH688iGW3qyeuuZrwUTKoS41eRgepXNstqQuNnR1qf3G3lMtqMTB4qkc15f5dsudtqyRFT/9MRP9KrQGuRIQd8yh5ZIbaM3O7Zyu4TGGnfJ3lkJdvSOjKKW5+RRXDYNBqMVT+Bcu+MRXDYjKwQo5+Oqov01uhhZNkja8kY2Z1cr0Z3TJ8yOooZt5ZClWP0x9OmGjYBM0MAAADwSURBVD+wN0VPm3LmxXPFqx7uM2HkHzPST2OSyK8c1nzKFfrW5qR6IwKPpujfuvTAWK3FEy8Fs+qEamEVPWkoa7hoADXStJdAaz6GrekV1J1YYzyQDAUTxNf7iWPNFxCgRprwjLTgY9iCLoGKcaylChVSS9p1S2IUDAAAAIAEBQMAAADJAwUDAAAAyQMFAwAAAMkDBQMAAADJAwUDAAAAyQMFAwAAAMkDBQMAAADJAwUDAAAAyQMFAwAAAMkDBQMAAADJAwUDAAAAyQMFAwAAAMkDBQMAAADJAwUDAAAAyQMFAwAAAMkDBQMAAADJ4/8B1Kbjc16O7OMAAAAASUVORK5CYII=" alt="" />

那么我们就用SetWindowLong 来改变 Header的 消息过程。

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------- static HWND hListViewHeader = NULL; //Header原来的窗口过程
static WNDPROC oldHeaderWindowProc = NULL; //Header的新窗口过程
LRESULT CALLBACK NewHeaderWindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
//先要用原来的窗口过程处理
LRESULT result = oldHeaderWindowProc(hwnd,uMsg,wParam,lParam);
//再处理HDM_LAYOUT消息
if (HDM_LAYOUT == uMsg)
{
LPHDLAYOUT phdmlayout = (LPHDLAYOUT)lParam;
//改变header的高度
phdmlayout->pwpos->cy = ;
//改变listview表格部分的高度
phdmlayout->prc->top = phdmlayout->pwpos->cy;
} return result;
} __fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender)
{
hListViewHeader = ListView_GetHeader(ListView1->Handle);
oldHeaderWindowProc = (WNDPROC)SetWindowLong(
hListViewHeader,GWL_WNDPROC,(LONG)NewHeaderWindowProc);
ListView1->Invalidate();
}
//---------------------------------------------------------------------------

我们会看到这样的效果

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAhIAAAECCAIAAAAkYanuAAAZIklEQVR4nO3deXTU1d3H8e+R1j6yI1BskWqEEILsi4hsQUBQVGRRwTViQWRflEWEDAQsiLiLVtGI4i4qUASXhyggIIpEuBU3ivuDIgZCZMky9/ljJpNfJMm9txbmWt7f8zo9rU3DBzwzbydbRWVt/E/RWodCIeH+vasqki3ysUiFX/c2FUS+EdEiS0W0SFjkfZF3Rf4lokXyRDaJrBfpVsb/vJlIvogWKRDRIlrkPJFuIlokXySr6L+6V6RyGe+htsghkfuL/mMdkerl/sZPFKlX7u8o8puqJ3JSuW9TXaS2iIhcJaJF2vy7v1bs6oqcWPKvfC6iRcaJiEhlkT0iWuQOES2SK5IgcpLISSJDRLTIftNvvKbIAREt8qDIhIA3RLTINoud9Yr+HhWIHAr8LTskcqjo72NMocgAu984x5V/ZMOXu0hEi9zg/jYJI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zAjG67HKvvzZ5UiG3bIBszIhuuxyv78WaXIhh2yATOy4Xqssj9/VimyYYdswIxsuB6r7M+fVYps2CEbMCMbrscq+/NnlSIbdsgGzMiG67HK/vxZpciGHbIBM7LheqyyP39WKbJhh2zAjGy4Hqvsz59VimzYIRswIxuuxyr782eVIht2yAbMyIbrscr+/FmlyIYdsgEzsuF6rLI/f1YpsmGHbMAsFArFfQNwDJANG2QDZvH+p0COO3YX94eb/8gGAMAB2QAAOCAbAAAHZAMA4IBsAAAckA0AgAOyAQBwQDYAAA7IBgDAAdkAADggGwAAB2QDAOCAbAAAHJANAIADsgEAcEA2AAAOyAYAwAHZAAA4IBsAAAdkAwDggGwAAByQDQCAA7IBAHBANgAADsgGAMAB2QAAOCAbAAAHZAMA4IBsAAAckA0AgAOyAQBwQDYAAA7IBgDAAdkAADggGwAAB2QDAOCAbAAAHJANAIADsgEAcPD/Yry6vZdC34gAAAAASUVORK5CYII=" alt="" />

  • 处理Header的背景色

可以在Header的窗口过程中编写WM_PAINT 消息处理函数。但是这样写,你会发现无法在Header上输出文字。准确的说,你绘制上去的文字

会莫名其妙的不见,比如,拉宽一下Header 中的某一列,文字就会消失边检。使得这种重绘不好控制;

正确的做法是这样

  1. 调用 Header_SetItem 函数(其实是一个macro) 将ListView的Header 的 format 属性,设置为 HDF_OWNERDRAW (默认是 HDF_STRING).
  2. 重写ListView 的消息过程。(不是Header的消息过程);
  3. 在ListView的消息过程中处理 WM_DRAWITEM 消息;(WM_DRAWITEM消息会包含要重绘的 区域,hdc,index,状态等等)
  4. 在Header 的 HDM_LAYOUT 消息处理过程,也要调用 Header_SetItem,将format消息设置为 HDF_OWERDRAW (否则,每次改变列宽,format属性就又变成HDF_STRING,导致无法重绘)

下面是实现的代码

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------- static HWND hListViewHeader = NULL; //Header原来的窗口过程
static WNDPROC oldHeaderWindowProc = NULL; //listView 原来的窗口过程
static WNDPROC oldListViewProc = NULL; //Header的新窗口过程
LRESULT CALLBACK NewHeaderWindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
//先要用原来的窗口过程处理
LRESULT result = oldHeaderWindowProc(hwnd,uMsg,wParam,lParam);
//再处理HDM_LAYOUT消息
if (HDM_LAYOUT == uMsg)
{
LPHDLAYOUT phdmlayout = (LPHDLAYOUT)lParam;
//改变header的高度
phdmlayout->pwpos->cy = ;
//改变listview表格部分的高度
phdmlayout->prc->top = phdmlayout->pwpos->cy;
} return result;
} LRESULT CALLBACK NewListViewWindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
if (uMsg == WM_DRAWITEM)
{
DRAWITEMSTRUCT* drawItemStruct = (DRAWITEMSTRUCT*)lParam;
HDC hdc = drawItemStruct->hDC;
int index = drawItemStruct->itemID;
RECT rect = drawItemStruct->rcItem; TBrush* brush = new TBrush();
TColor fontColor = clBlack;
if (index == )
{
brush->Color = clRed;
fontColor = clWhite;
} if (index == )
{
brush->Color = clYellow;
fontColor = clBlue;
} if (index == )
{
brush->Color = clBlue;
fontColor = clWhite;
} if (index == )
{
brush->Color = clLime;
fontColor = clBlue;
} FillRect(hdc,&rect,brush->Handle);
delete brush; SetTextColor(hdc,fontColor);
SetBkMode(hdc,TRANSPARENT);
//获取文本
HDITEM hditem= {};
char buf[] = {};
hditem.mask = HDI_TEXT;
hditem.pszText = buf;
hditem.cchTextMax = ;
Header_GetItem(hListViewHeader,index,&hditem); DrawText(hdc,hditem.pszText,strlen(hditem.pszText),&rect,
DT_CENTER |DT_VCENTER |DT_SINGLELINE); } return oldListViewProc(hwnd,uMsg,wParam,lParam);
} __fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void SetHDItem()
{
if (hListViewHeader == NULL)
{
return;
} HDITEM hditem;
hditem.mask = HDI_FORMAT;
hditem.fmt = HDF_OWNERDRAW; //默认是 HDF_STRING int count = Header_GetItemCount(hListViewHeader);
for (int i = ; i < count ;i++)
{
Header_SetItem(hListViewHeader,i,&hditem);
}
} void __fastcall TForm1::FormCreate(TObject *Sender)
{
hListViewHeader = ListView_GetHeader(ListView1->Handle); oldHeaderWindowProc = (WNDPROC)SetWindowLong(
hListViewHeader,GWL_WNDPROC,(LONG)NewHeaderWindowProc); oldListViewProc = (WNDPROC)SetWindowLong(
ListView1->Handle,GWL_WNDPROC,(LONG)NewListViewWindowProc); SetHDItem(); ListView1->Invalidate();
}
//---------------------------------------------------------------------------

显示效果如下

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfkAAAEFCAIAAABvhAnRAAATjUlEQVR4nO3deZDU5Z3H8acWi1qruBTJxMUxISIDw+AAgggOlzBCHEUuFUQ5BUS5D7kEmstwiIoHahQjHvGK64EoSpW1MbuFkSSr7LMBD1wEkUtoGCYIM9P97B/d9DQ6mOd5mLEfv7w/9fqb+pZV/a5ftc0PldN0ypi/lprY14u7jauVMzZ7zKelxphjny+etu6Pm/WDN01uufwbY2I7399Tbkz0w20lxkRfXNSg2fi6ueN/NePruDF7H517Xu6Ees0n1Gs+4ZzmE5Pyks7Nm3hu3qRzWyTVT7hkcsp5l0w+L3/yeflTEhoktJzSoOXUBi2n/iyhVcq0rFbTslpX+HnrO39+6UnObzM93b+1TZiR0PCylJkNL5vZsN3MCyrMuuDyWdnp2s/Kbj/7wpQOsy/sMPsXHe5KuiLpl1fMSSqY88uCOY0K5jQqmNuoYG6jjnMbdZz7q5RO8xIuSug876LOkYs6RxondEmY37jL/Iu7zL+4a4UmXRc0ubJCzpULcrotTNe0+8Km3RelNCtMWdyscHGzqxbnVrg7t8fdzU/ym7yeJ/v1khbprl5yydVLLrl6aVLR0kuKluYXLc0vWpZftCz/mmX51yxrmbS85bVJrRJ6LW/V655Wve5pnXBdwopLE3qn3Num971t+lRo2+fetn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AoAP2BADQAXsCAOiAPQEAdMCeAAA6YE8AAB2wJwCADtgTAEAH7AkAoAP2BADQAXsCAOiAPQEAdMCeAAA6YE8AAB2wJwCADtgTAEAH7AkAoAP2BADQAXsCAOiAPQEAdMCeAAA6YE8AAB2wJwCADtgTAEAH7AkAoAP2BADQAXsCAOiAPQEAdMCeAAA6YE8AAB2wJwCADtgTAEAH7AkAoAP2BADQAXsCAOiAPQEAdMCeAAA6YE8AAB2wJwCADtgTAEAH7AkAoAP2BADQAXsCAOiAPQEAdMCeAAA6YE8AAB2wJwCADtgTAEAH7AkAoAP2BADQAXsCAOiAPQEAdMCeAAA6YE8AAB2wJwCADtgTAEAH7AkAoAP2BADQ4f8BJvK7AfKXGlcAAAAASUVORK5CYII=" alt="" />

所以需要有上述步骤中第4步,在HDM_LAYOUT消息中加入SetHDItem 函数调用

最终代码

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------- static HWND hListViewHeader = NULL; //Header原来的窗口过程
static WNDPROC oldHeaderWindowProc = NULL; //listView 原来的窗口过程
static WNDPROC oldListViewProc = NULL; void SetHDItem()
{
if (hListViewHeader == NULL)
{
return;
} HDITEM hditem;
hditem.mask = HDI_FORMAT;
hditem.fmt = HDF_OWNERDRAW; //默认是 HDF_STRING int count = Header_GetItemCount(hListViewHeader);
for (int i = ; i < count ;i++)
{
Header_SetItem(hListViewHeader,i,&hditem);
}
} //Header的新窗口过程
LRESULT CALLBACK NewHeaderWindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
//先要用原来的窗口过程处理
LRESULT result = oldHeaderWindowProc(hwnd,uMsg,wParam,lParam);
//再处理HDM_LAYOUT消息
if (HDM_LAYOUT == uMsg)
{
LPHDLAYOUT phdmlayout = (LPHDLAYOUT)lParam;
//改变header的高度
phdmlayout->pwpos->cy = ;
//改变listview表格部分的高度
phdmlayout->prc->top = phdmlayout->pwpos->cy;
//将HDF_STRING 重新设置为 HDF_OWNERDRAW
SetHDItem();
} return result;
} LRESULT CALLBACK NewListViewWindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
if (uMsg == WM_DRAWITEM)
{
DRAWITEMSTRUCT* drawItemStruct = (DRAWITEMSTRUCT*)lParam;
HDC hdc = drawItemStruct->hDC;
int index = drawItemStruct->itemID;
RECT rect = drawItemStruct->rcItem; TBrush* brush = new TBrush();
TColor fontColor = clBlack;
if (index == )
{
brush->Color = clRed;
fontColor = clWhite;
} if (index == )
{
brush->Color = clYellow;
fontColor = clBlue;
} if (index == )
{
brush->Color = clBlue;
fontColor = clWhite;
} if (index == )
{
brush->Color = clLime;
fontColor = clBlue;
} FillRect(hdc,&rect,brush->Handle);
delete brush; SetTextColor(hdc,fontColor);
SetBkMode(hdc,TRANSPARENT);
//获取文本
HDITEM hditem= {};
char buf[] = {};
hditem.mask = HDI_TEXT;
hditem.pszText = buf;
hditem.cchTextMax = ;
Header_GetItem(hListViewHeader,index,&hditem); DrawText(hdc,hditem.pszText,strlen(hditem.pszText),&rect,
DT_CENTER |DT_VCENTER |DT_SINGLELINE); } return oldListViewProc(hwnd,uMsg,wParam,lParam);
} __fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender)
{
hListViewHeader = ListView_GetHeader(ListView1->Handle); oldHeaderWindowProc = (WNDPROC)SetWindowLong(
hListViewHeader,GWL_WNDPROC,(LONG)NewHeaderWindowProc); oldListViewProc = (WNDPROC)SetWindowLong(
ListView1->Handle,GWL_WNDPROC,(LONG)NewListViewWindowProc); SetHDItem(); ListView1->Invalidate();
}
//---------------------------------------------------------------------------

---2016年6月15日更新

上个版本虽然实现了效果,但是有一个bug,双击列头中间的分割区域,会导致背景色丢失;

aaarticlea/png;base64,iVBORw0KGgoAAAANS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要在默认消息处理完之后执行
LRESULT CALLBACK NewListViewWindowProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
if (uMsg == WM_DRAWITEM)
{
DRAWITEMSTRUCT* drawItemStruct = (DRAWITEMSTRUCT*)lParam;
HDC hdc = drawItemStruct->hDC;
int index = drawItemStruct->itemID;
RECT rect = drawItemStruct->rcItem; TBrush* brush = new TBrush();
TColor fontColor = clBlack;
if (index == )
{
brush->Color = clRed;
fontColor = clWhite;
} if (index == )
{
brush->Color = clYellow;
fontColor = clBlue;
} if (index == )
{
brush->Color = clBlue;
fontColor = clWhite;
} if (index == )
{
brush->Color = clLime;
fontColor = clBlue;
} FillRect(hdc,&rect,brush->Handle);
delete brush; SetTextColor(hdc,fontColor);
SetBkMode(hdc,TRANSPARENT);
//获取文本
HDITEM hditem= {};
char buf[] = {};
hditem.mask = HDI_TEXT;
hditem.pszText = buf;
hditem.cchTextMax = ;
Header_GetItem(hListViewHeader,index,&hditem); DrawText(hdc,hditem.pszText,strlen(hditem.pszText),&rect,
DT_CENTER |DT_VCENTER |DT_SINGLELINE); } LRESULT result = oldListViewProc(hwnd,uMsg,wParam,lParam); //--双击列的分隔区事件
if (uMsg == WM_NOTIFY)
{
NMHDR* nmhdr = (NMHDR*)lParam;
if (nmhdr != NULL &&
nmhdr->hwndFrom == hListViewHeader &&
nmhdr->code == HDN_DIVIDERDBLCLICK)
{
//将HDF_STRING 重新设置为 HDF_OWNERDRAW
SetHDItem();
}
} return result;
}

之后双击分隔区的效果

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAU0AAADpCAIAAAAvaPLfAAAK10lEQVR4nO2df2xV9RmH36ykGQlSCCENgW4hQXGlBIIQ51Jr2WA0aWIcGoWwiRiRZXEEFh1mhKUDtuiQbDBHdFEjDqPTLCxBotiEbLoFtG4DdjNAfqyCCLQrl5ab0t7ec979IU6ht4vQd+e8/d7nyfNn03xObp+e23vP6ZXMvr2IGLaS+gJE/H9L54jhS+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wxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXzpHDF86RwxfOkcMXz/A6hUezu4OLpZAAAAAElFTkSuQmCC" alt="" />

TListView Header重绘和高度设置的更多相关文章

  1. Android重绘ListView高度

    Android重绘ListView高度 经常会有这样需求,需要ListView默认将所有的条目显示出来,这就需要外层使用ScrollView,ScrollView里面放置一个重绘高度的ListView ...

  2. iOS 视图:重绘与UIScrollView(内容根据iOS编程编写)

    我们继续之前的 Hypnosister 应用,当用户开始触摸的时候,圆形的颜色会改变. 首先,在 JXHypnosisView 头文件中声明一个属性,用来表示圆形的颜色. #import " ...

  3. 重绘TabControl

    本文转载自:http://blog.csdn.net/conmajia/article/details/7596718 作者:野比 (conmajia@gmail.com) 时间:May, 2012 ...

  4. 重绘Winform窗体

    本文转载自:http://www.cnblogs.com/encoding/p/5603080.html 按照惯例,先来几张样例图(注:为了展示窗口阴影效果,截图范围向外扩展了些,各位凭想象吧). 还 ...

  5. ListBox重绘

    .NET Framework 类库  ListBox.ItemHeight 属性 当 DrawMode 属性设置为 DrawMode.OwnerDrawFixed 时,所有项具有相同的高度.当 Dra ...

  6. IOS中对图片进行重绘处理的方法总结

    一.CGImageRef是什么 CGImageRef是定义在QuartzCore框架中的一个结构体指针,用C语言编写.在CGImage.h文件中,我们可以看到下面的定义: ? 1 typedef st ...

  7. 《Android内核剖析》读书笔记 第13章 View工作原理【View重绘过程】

    计算视图大小的过程(Measure) 视图大小,准确的来说应该是指视图的布局大小:我们在layout.xml中为每个UI控件设置的layout_width/layout_height两个属性被用来设置 ...

  8. [Android FrameWork 6.0源码学习] View的重绘过程

    View绘制的三部曲,  测量,布局,绘画今天我们分析测量过程 view的测量是从ViewRootImpl发起的,View需要重绘,都是发送请求给ViewRootImpl,然后他组织重绘在重绘的过程中 ...

  9. 重绘(redraw或repaint),重排(reflow)

    浏览器运行机制图: 浏览器的运行机制:layout:布局: 1.构建DOM树(parse):渲染引擎解析HTML文档,首先将标签转换成DOM树中的DOM node(包括js生成的标签)生成内容树(Co ...

随机推荐

  1. 【转】Styling And Animating SVGs With CSS

    原文转自:http://www.smashingmagazine.com/2014/11/03/styling-and-animating-svgs-with-css/?utm_source=CSS- ...

  2. C++学习笔记16:Linux系统编程基础1

    参数列表 Linux命令行规范 短参数:以单横开头,后跟单一字符,例如:ls -h 长参数:以双横开头,后跟字符串,例如:ls --help 程序访问参数列表的方法: 主函数的参数argc和argv ...

  3. False Discovery Rate, a intuitive explanation

    [转载请注明出处]http://www.cnblogs.com/mashiqi Today let's talk about a intuitive explanation of Benjamini- ...

  4. libevent库1.4升级到2.0时无法flush的解决办法

    libevent的接口兼容性做的还算不错,基本上替换一下就转到新版本了.但是,强制flush数据的时候出了问题.目前的应用场景是,遇到顶号登录这种情形,先用bufferevent_write向客户端发 ...

  5. 解决CentOS6.4 Docker "Couldn't connect to Docker daemon ..." 问题

    OS: CentOS6.4 #uname -r 2.6.32-504.1.3.el6.x86_64 安装完毕fig,并完成相应配置时执行如下命令出错(fig安装参见:http://www.fig.sh ...

  6. C++ Primer : 第十三章 : 动态内存管理类

    /* StrVec.h */ #ifndef _STRVEC_H_ #define _STRVEC_H_ #include <memory> #include <string> ...

  7. kuangbin_SegTree E (HDU 1698)

    POJ服务器炸了 还没好呢 然后就只能跳掉一些题目了 这题也是成段更新模板题 本来lazy标记不是很明白 后来学长上课讲了一下就知道原理了 回去看看代码很容易就理解了 #include <cst ...

  8. (转)深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0

      深度学习主机环境配置: Ubuntu16.04+Nvidia GTX 1080+CUDA8.0 发表于2016年07月15号由52nlp 接上文<深度学习主机攒机小记>,这台GTX10 ...

  9. java对象序列化byte[] and byte[]反序列化对象--转

    import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOExceptio ...

  10. INNO 补丁制作技术, 打开 INNO 补丁制作方法的第一页

    INNO 补丁制作技术, 打开 INNO 补丁制作方法的第一页 作者:xin 日期:2005-09-23 字体大小: 小 中 大   VPatch 在 INNO 中的应用. VPatch 属于专为NS ...