1

我正在使用一个HorizontalList组件来显示图像列表,您可以从另一个组件中拖动图像加入列表,这一切都很好。

如果我这样做,list.showDropFeedback(event)我会在图像顶部看到一个难看的黑条HorizontalList- 我真正想要的是图像左/右的一条线,新的实际上将坐在那里。

我想我需要定义一个自定义 DropFeedback 来覆盖默认值。有谁知道是否有办法实现这一目标?

谢谢!

4

5 回答 5

3

Yuo 可以通过重写 showDropFeedback() 方法来解决它。我的代码如下:

    import mx.controls.HorizontalList;
import mx.controls.listClasses.IListItemRenderer;
import mx.core.mx_internal;
import mx.events.DragEvent;

use namespace mx_internal;

public class HList extends HorizontalList
{
    public function HList()
    {
        super();                        
    }   


        override public function showDropFeedback(event:DragEvent):void
        {

           super.showDropFeedback(event);

            dropIndicator.setActualSize(rowHeight - 4, 4);
            DisplayObject(dropIndicator).rotation = 90;

        }



}
于 2009-04-23T09:23:09.293 回答
2

我最终通过在我的应用程序样式中添加以下内容来解决这个问题..

HorizontalList {
 dropIndicatorSkin: ClassReference("com.package.HorizontalListDropIndicator");
} 

并创建我的自定义皮肤..

package com.package {

 import flash.display.Graphics;
 import mx.skins.ProgrammaticSkin;

 public class HorizontalListDropIndicator extends ProgrammaticSkin {

  public function HorizontalListDropIndicator() {
   super();
  }

  override protected function updateDisplayList(w:Number, h:Number):void {  
   super.updateDisplayList(w, h);

   var g:Graphics = graphics;

   g.clear();
   g.lineStyle(2, 0xFF0000);

   g.moveTo(0, 0);
   g.lineTo(0, 250);

  }
 }
}
于 2009-03-12T11:52:11.643 回答
2

看起来这是 Flex 框架中的一个错误:

Flex Builder 3/sdks/3.3.0/frameworks/projects/framework/src/mx/controls/HorizontalList.as(第 95-105 行)

public function HorizontalList()
{
    super();

    _horizontalScrollPolicy = ScrollPolicy.AUTO;
    _verticalScrollPolicy = ScrollPolicy.OFF;

    direction = TileBaseDirection.VERTICAL;
    maxRows = 1;
    defaultRowCount = 1;
}

请注意,Horizo​​ntalList的构造函数将方向值初始化为Vertical

一种快速简便的解决方法是direction="horizontal"在 MXML 中简单地指定:

<mx:HorizontalList id="fooLst" direction="horizontal" dataProvider="{foo}" />

如果此错误尚未修复(并等待下一个版本),我会感到惊讶,但我会检查Flex SDK 错误数据库并提交报告,如果它没有记录在案。

于 2009-05-19T18:55:05.070 回答
1

有一个名为 dropIndicatorSkin 的样式属性,它控制当您在基于列表的组件上拖动时显示的线条的外观。来自 adobe 文档:

下降指示器皮肤

用于指示可以将拖动项目放置在何处的外观。当 ListBase 派生组件是拖放操作中的潜在放置目标时,对该showDropFeedback()方法的调用会生成此类的一个实例,并将其itemRenderer放置在项目上方一个像素处,如果发生放置,则掉落物品之后的物品。默认值为mx.controls.listClasses.ListDropIndicator

所有功能都内置在 Horizo​​ntalList 中以执行您的要求,但 Horizo​​ntalList 中似乎存在一个错误,它没有将其方向属性设置为水平。

您需要做的就是将 direction="horizo​​ntal" 放在 mxml 声明中,它会将 dropIndicatorSkin 旋转 90 度并将其放置在项目之间而不是它们之上:

<mx:HorizontalList ... direction="horizontal" ... />
于 2009-02-26T17:41:50.610 回答
0

谢谢,这似乎按预期旋转了 dropIndicator,但会产生其他非常意外的行为。列表上的水平滚动条突然消失,将一个项目拖到列表上使其直接跳到最后......感觉就像我快到了,但不完全!

我的 AS3 代码....

// in constructor... (extends HorizontalList)
this.direction = "horizontal";

this.addEventListener(DragEvent.DRAG_ENTER, onDragEnter);
this.addEventListener(DragEvent.DRAG_OVER, onDragOver);
this.addEventListener(DragEvent.DRAG_EXIT, onDragExit);
this.addEventListener(DragEvent.DRAG_DROP, onDragDrop);

private function onDragEnter(event:DragEvent):void {
    event.preventDefault();
    if (event.dragSource.hasFormat("treeItems") || event.dragSource.hasFormat("items")) {
        DragManager.acceptDragDrop(event.target as UIComponent);
    }
    this.showDropFeedback(event);
}

public function onDragOver(event:DragEvent):void {
    event.preventDefault();
    this.showDropFeedback(event);
}

public function onDragExit(event:DragEvent):void {
    event.preventDefault();
    this.showDropFeedback(event);
}

private function onDragDrop(event:DragEvent):void {
    event.preventDefault();
    this.hideDropFeedback(event);
    //....
}
于 2009-02-27T11:35:31.497 回答