Flex Drop元素太大时

问题描述:

在Flex Mobile中,我在操作栏中有几个按钮。在屏幕非常小的设备上(例如HTC Wildfire),不能显示所有按钮。有没有办法让Flex在不适合时隐藏元素?我知道这是可能通过使用状态和测试屏幕的宽度,但我希望有另一种方式..Flex Drop元素太大时

+0

您是否在操作栏中使用基于%的宽度布局来显示内容?如果你是和内容仍然被放弃,你将不得不做一些与国家。重新访问您的设计并查看是否有可能减少操作栏中使用的空间 – francis 2012-04-13 02:11:11

+0

我使用的是固定宽度,因为按钮全都具有图标,这可能也值得。重新访问并不是必需的,因为Wildfire是afaik唯一不能显示所有按钮的设备 – MorbZ 2012-04-13 14:56:09

这里有一个非常简单的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布局类的所有功能的布局不是微不足道的。但是你当然可以做一些简单的事情,像上面这样,遍历子对象,设置它们的大小/位置,在这种情况下,不会打扰不适合渲染的东西。

+0

由于某些原因,当我将此置于actionLayout中时,所有元素都隐藏起来。我不得不调整你的代码。现在它也适用于操作栏。谢谢 – MorbZ 2012-04-13 14:44:57

+0

太棒了!您可能想要编辑答案并添加您为其使用w/ActionBar(actionLayout属性)时所做的调整。我对它进行了测试,但它没有任何问题:) – 2012-04-13 15:00:15

+0

我把它编码得很快而且很脏,但它起作用,我会将它添加到您的答案中 – MorbZ 2012-04-13 15:04:49

您可以检查ApplicationDPI值;并隐藏更高分辨率的显式内容。大多数片剂提供160dpi;而大多数手机提供240dpi。 iPhone 4提供320dpi的屏幕。我不确定iPad Retina显示屏幕。

+0

纯粹使用基于dpi的布局将会棘手。 iPad 3和即将发布的1080p Android桌面的分辨率大约为260dpi(准确的说,iPad的分辨率为264),因此Flex会将其标记为240dpi。 – AlBirdie 2012-04-13 06:31:53

+0

@Al_Birdy同意;它确实取决于你想要做什么,你想要的目标以及代码需要的“未来证明”。 – JeffryHouser 2012-04-13 11:56:20