Flex Drop元素太大时
在Flex Mobile中,我在操作栏中有几个按钮。在屏幕非常小的设备上(例如HTC Wildfire),不能显示所有按钮。有没有办法让Flex在不适合时隐藏元素?我知道这是可能通过使用状态和测试屏幕的宽度,但我希望有另一种方式..Flex Drop元素太大时
这里有一个非常简单的Spark布局类是水平排列的对象,下探赢得”任何项目不适合。
package
{
import mx.core.ILayoutElement;
import spark.layouts.supportClasses.LayoutBase;
public class DroppableHorizontalLayout extends LayoutBase
{
private static const PADDING:Number = 5;
public function DroppableHorizontalLayout()
{
super();
}
override public function updateDisplayList(width:Number, height:Number):void
{
// super.updateDisplayList(width,height); // super method doesn't do anything
var currentXCoordinate:Number = 0;
var numKids:int = target.numChildren;
for (var i:int=0; i < numKids; i++)
{
var currentItem:ILayoutElement = target.getElementAt(i);
var itemWidth:Number = currentItem.getPreferredBoundsWidth();
if (currentXCoordinate + itemWidth < width)
{
currentItem.setLayoutBoundsSize(itemWidth, currentItem.getPreferredBoundsHeight());
currentItem.setLayoutBoundsPosition(currentXCoordinate, 0); // or whatever the Y coordinate should be
currentXCoordinate = currentXCoordinate + itemWidth + PADDING;
}
else
{
break; // no reason to keep iterating, nothing else will fit...
}
}
}
}
}
编写具有典型Flex布局类的所有功能的布局不是微不足道的。但是你当然可以做一些简单的事情,像上面这样,遍历子对象,设置它们的大小/位置,在这种情况下,不会打扰不适合渲染的东西。
您可以检查ApplicationDPI值;并隐藏更高分辨率的显式内容。大多数片剂提供160dpi;而大多数手机提供240dpi。 iPhone 4提供320dpi的屏幕。我不确定iPad Retina显示屏幕。
纯粹使用基于dpi的布局将会棘手。 iPad 3和即将发布的1080p Android桌面的分辨率大约为260dpi(准确的说,iPad的分辨率为264),因此Flex会将其标记为240dpi。 – AlBirdie 2012-04-13 06:31:53
@Al_Birdy同意;它确实取决于你想要做什么,你想要的目标以及代码需要的“未来证明”。 – JeffryHouser 2012-04-13 11:56:20
您是否在操作栏中使用基于%的宽度布局来显示内容?如果你是和内容仍然被放弃,你将不得不做一些与国家。重新访问您的设计并查看是否有可能减少操作栏中使用的空间 – francis 2012-04-13 02:11:11
我使用的是固定宽度,因为按钮全都具有图标,这可能也值得。重新访问并不是必需的,因为Wildfire是afaik唯一不能显示所有按钮的设备 – MorbZ 2012-04-13 14:56:09