Android 单机器人上的工具栏
你们知道一些例子吗,那个些记录了如何使用“mono for android”工具栏开发的屏幕广播Android 单机器人上的工具栏,android,xamarin.android,Android,Xamarin.android,你们知道一些例子吗,那个些记录了如何使用“mono for android”工具栏开发的屏幕广播 我想开发一个小工具栏,我正在寻找正确的编码方法?这里是仪表板,如果您或其他人需要ActionBar,这里是一个 公共类仪表板布局:视图组 { 私有常数不均匀网格惩罚乘数=10; 私人住宅小区(住宅小区);; 私人住宅; 公用仪表板布局(IntPtr doNotUse,JNIHandle所有权转移):基本(doNotUse,转移) { } 公共仪表板布局(上下文) :基本(上下文) { } 公用仪表板
我想开发一个小工具栏,我正在寻找正确的编码方法?这里是仪表板,如果您或其他人需要ActionBar,这里是一个
公共类仪表板布局:视图组
{
私有常数不均匀网格惩罚乘数=10;
私人住宅小区(住宅小区);;
私人住宅;
公用仪表板布局(IntPtr doNotUse,JNIHandle所有权转移):基本(doNotUse,转移)
{
}
公共仪表板布局(上下文)
:基本(上下文)
{
}
公用仪表板布局(上下文、IAttributeSet属性)
:base(上下文、属性)
{
}
公共仪表板布局(上下文上下文、IAttributeSet属性、int-defStyle)
:base(上下文、属性、定义样式)
{
}
测量时受保护的覆盖无效(int-widthMeasureSpec、int-heightMeasureSpec)
{
_mMaxChildWidth=0;
_mMaxChildHeight=0;
//测量一次以找到最大子大小。
var childwidthmasurespec=MeasureSpec.MakeMeasureSpec(
MeasureSpec.GetSize(widthMeasureSpec)、MeasureSpecMode.AtMost);
var childheightmeasurept=measurept.makemeasurept(
MeasureSpec.GetSize(widthMeasureSpec)、MeasureSpecMode.AtMost);
var count=ChildCount;
对于(变量i=0;i
工具栏下的“操作栏”是什么意思
public class DashboardLayout : ViewGroup
{
private const int UNEVEN_GRID_PENALTY_MULTIPLIER = 10;
private int _mMaxChildWidth;
private int _mMaxChildHeight;
public DashboardLayout(IntPtr doNotUse, JniHandleOwnership transfer) : base(doNotUse, transfer)
{
}
public DashboardLayout(Context context)
: base(context)
{
}
public DashboardLayout(Context context, IAttributeSet attrs)
: base(context, attrs)
{
}
public DashboardLayout(Context context, IAttributeSet attrs, int defStyle)
: base(context, attrs, defStyle)
{
}
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
_mMaxChildWidth = 0;
_mMaxChildHeight = 0;
// Measure once to find the maximum child size.
var childWidthMeasureSpec = MeasureSpec.MakeMeasureSpec(
MeasureSpec.GetSize(widthMeasureSpec), MeasureSpecMode.AtMost);
var childHeightMeasureSpec = MeasureSpec.MakeMeasureSpec(
MeasureSpec.GetSize(widthMeasureSpec), MeasureSpecMode.AtMost);
var count = ChildCount;
for (var i = 0; i < count; i++)
{
var child = GetChildAt(i);
if (child.Visibility == ViewStates.Gone)
{
continue;
}
child.Measure(childWidthMeasureSpec, childHeightMeasureSpec);
_mMaxChildWidth = Math.Max(_mMaxChildWidth, child.MeasuredWidth);
_mMaxChildHeight = Math.Max(_mMaxChildHeight, child.MeasuredHeight);
}
// Measure again for each child to be exactly the same size.
childWidthMeasureSpec = MeasureSpec.MakeMeasureSpec(
_mMaxChildWidth, MeasureSpecMode.Exactly);
childHeightMeasureSpec = MeasureSpec.MakeMeasureSpec(
_mMaxChildHeight, MeasureSpecMode.Exactly);
for (int i = 0; i < count; i++)
{
var child = GetChildAt(i);
if (child.Visibility == ViewStates.Gone)
{
continue;
}
child.Measure(childWidthMeasureSpec, childHeightMeasureSpec);
}
SetMeasuredDimension(
ResolveSize(_mMaxChildWidth, widthMeasureSpec),
ResolveSize(_mMaxChildHeight, heightMeasureSpec));
}
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
var width = r - l;
var height = b - t;
var count = ChildCount;
// Calculate the number of visible children.
var visibleCount = 0;
for (var i = 0; i < count; i++)
{
var child = GetChildAt(i);
if (child.Visibility == ViewStates.Gone)
{
continue;
}
++visibleCount;
}
if (visibleCount == 0)
{
return;
}
// Calculate what number of rows and columns will optimize for even horizontal and
// vertical whitespace between items. Start with a 1 x N grid, then try 2 x N, and so on.
var bestSpaceDifference = int.MaxValue;
// Horizontal and vertical space between items
int hSpace;
int vSpace;
var cols = 1;
int rows;
while (true)
{
rows = (visibleCount - 1) / cols + 1;
hSpace = ((width - _mMaxChildWidth * cols) / (cols + 1));
vSpace = ((height - _mMaxChildHeight * rows) / (rows + 1));
var spaceDifference = Math.Abs(vSpace - hSpace);
if (rows * cols != visibleCount)
{
spaceDifference *= UNEVEN_GRID_PENALTY_MULTIPLIER;
}
if (spaceDifference < bestSpaceDifference)
{
// Found a better whitespace squareness/ratio
bestSpaceDifference = spaceDifference;
// If we found a better whitespace squareness and there's only 1 row, this is
// the best we can do.
if (rows == 1)
{
break;
}
}
else
{
// This is a worse whitespace ratio, use the previous value of cols and exit.
--cols;
rows = (visibleCount - 1) / cols + 1;
hSpace = ((width - _mMaxChildWidth * cols) / (cols + 1));
vSpace = ((height - _mMaxChildHeight * rows) / (rows + 1));
break;
}
++cols;
}
// Lay out children based on calculated best-fit number of rows and cols.
// If we chose a layout that has negative horizontal or vertical space, force it to zero.
hSpace = Math.Max(0, hSpace);
vSpace = Math.Max(0, vSpace);
// Re-use width/height variables to be child width/height.
width = (width - hSpace * (cols + 1)) / cols;
height = (height - vSpace * (rows + 1)) / rows;
var visibleIndex = 0;
for (var i = 0; i < count; i++)
{
var child = GetChildAt(i);
if (child.Visibility == ViewStates.Gone)
{
continue;
}
var row = visibleIndex / cols;
var col = visibleIndex % cols;
var left = hSpace * (col + 1) + width * col;
var top = vSpace * (row + 1) + height * row;
child.Layout(left, top,
(hSpace == 0 && col == cols - 1) ? r : (left + width),
(vSpace == 0 && row == rows - 1) ? b : (top + height));
++visibleIndex;
}
}
}