简体   繁体   English

Flex Mobile:如何查看皮肤?

[英]Flex Mobile : How to skin view?

I would like to know if it's possible to skin view for my Flex mobile application : 我想知道是否可以对Flex 移动应用程序进行外观查看:

My ActivityView.as 我的ActivityView.as

public class ActivityView extends View

My ActivityViewSkin.mxml (It skin associated) 我的ActivityViewSkin.mxml (与皮肤相关)

<?xml version="1.0" encoding="utf-8"?>
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
    xmlns:s="library://ns.adobe.com/flex/spark">

<fx:Metadata>   
    [HostComponent("com.corp.views.activity.ActivityView")]
    ...

It's a good way for mobile development ? 这是进行移动开发的好方法吗?

And how can I use this in this skin : 我该如何在皮肤上使用它:

<s:navigationContent>

Thank you very much ! 非常感谢你 !

Anthony 安东尼

no. 没有。 Spark skin is not optimized for mobile. Spark皮肤并未针对移动设备进行优化。 you should use MobileSkin . 您应该使用MobileSkin。 (Action script only). (仅动作脚本)。

I have been looking for similar information, however everything I can deduce from documentation and blogs implies that MobileSkin is something you do for component-level skinning (eg buttons, lists, itemRenderers, etc.), things that would be used many times throughout the app. 我一直在寻找类似的信息,但是我可以从文档和博客中得出的一切都暗示,MobileSkin是您为组件级外观(例如按钮,列表,itemRenderer等)所做的事情,在整个过程中会被多次使用应用程式。

THe other reason to think you might be able to get away with skinning your View via MXML is that all the Views I have seen code for are done so declaratively (MXML) and by skinning the View subclass using just the Skin class, you are only adding one more layer of hierarchy via the contentGroup in most skinnableContainer skins. 认为您可以通过MXML皮肤化视图的另一个原因是,我见过的所有视图都是以声明方式(MXML)完成的,并且仅使用Skin类对View子类进行皮肤化,通过大多数skinnableContainer外观中的contentGroup添加一层层次结构。

If you are using spark.components.View, then you are using a skin associated with as it is a SkinnableContainer. 如果使用的是spark.components.View,则使用的外观与之关联,因为它是SkinnableContainer。 It is NOT a simple group as you might think. 您可能并不认为这是一个简单的小组。

I dunno, I am kinda at a loss as to where to focus my efforts. 我不知道,我对将精力集中在什么地方感到困惑。 I am sure performance implications (if any) will rear their heads way later in the development stage. 我确信性能影响(如果有的话)将在开发阶段的晚些时候发挥作用。

From experience so far, you don't skin the View. 根据到目前为止的经验,您不会对View蒙皮。 You skin the ViewNavigatorApplication. 您为ViewNavigatorApplication蒙皮。 First, create the custom skin: 首先,创建自定义外观:

public class DViewNavigatorApplicationSkin extends ViewNavigatorApplicationSkin
{
    [Embed(source="assets/wine_240.jpg")]
    protected var cornerImage:Class;

    public function DViewNavigatorApplicationSkin()
    {
        super();            
    }


    override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void
    {   
        graphics.beginFill(0x000000);
        graphics.drawRect(0,0, unscaledWidth, unscaledHeight);
        graphics.endFill();
        var ba:BitmapAsset = new cornerImage() as BitmapAsset;
        var translateMatrix:Matrix = new Matrix();
        translateMatrix.tx = unscaledWidth - ba.width;
        translateMatrix.ty = unscaledHeight - ba.height;
        graphics.beginBitmapFill(ba.bitmapData, translateMatrix);
        graphics.drawRect(unscaledWidth - ba.width + 1, unscaledHeight - ba.height + 1, ba.width, ba.height);
        graphics.endFill();

    }

The contents of drawBackground docks the image to the lower right-hand corner of the display. drawBackground的内容将图像停靠在显示器的右下角。 You can draw anything in this function. 您可以在此函数中绘制任何内容。

Then in the theme.css: 然后在theme.css中:

s|ViewNavigatorApplication
{
    color: #ffffff;
    focusColor: #ff9999;
    skinClass:  ClassReference("com.domain.skins.mobile.ThemeName.DViewNavigatorApplicationSkin");
}

s|View
{
    backgroundAlpha: 0;
}

You draw the background image on the application itself. 您在应用程序本身上绘制背景图像。 You then make the View totally transparent so that you can see the background image through it. 然后,您可以使“视图”完全透明,以便可以通过它查看背景图像。

It may be possible to skin each individual view, but so far, it seems more practical to skin the application instead. 可以对每个单独的视图进行蒙皮,但是到目前为止,对应用程序进行蒙皮似乎更为实用。

It is kinda late to answer this question. 回答这个问题有点晚了。 Actually, we can use Spark Skin to skin the View component without any problem. 实际上,我们可以使用Spark Skin来为View组件设置外观,而不会出现任何问题。 View is just a subclass of SkinnableContainer (which is subclass of SkinnableComponent) so by default, whatever content you add directly to the MXML of View component will be added to contenGroup of SkinnableContainer. View只是SkinnableContainer的子类(这是SkinnableComponent的子类),因此默认情况下,直接添加到View的MXML组件中的任何内容都将添加到SkinnableContainer的contenGroup中。

I have added an example to skin the View using Spark Skin: 我添加了一个使用Spark Skin皮肤化View的示例:

Main Application: 主要应用:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" applicationDPI="160">
<fx:Script>
    <![CDATA[
        import com.accessdigital.core.SimpleView;
    ]]>
</fx:Script>
<fx:Style>
    @namespace s "library://ns.adobe.com/flex/spark";
    @namespace core "com.accessdigital.core.*";
    core|SimpleView{
        skinClass   : ClassReference("skin.view.Skin_SimpleView");
    }
</fx:Style>
<s:ViewNavigator width="100%" height="100%"
                 firstView="{SimpleView}">

</s:ViewNavigator>
</s:Application>

View Class 查看课程

public class SimpleView extends View
{
    public function SimpleView()
    {
        super();
    }

    [SkinPart(required="true")]
    public var myButton:Button;

    override protected function createChildren():void{
        super.createChildren();
        var anotherButton:Button = new Button();
        anotherButton.label = "Another button";
        anotherButton.addEventListener(MouseEvent.CLICK, onAnotherButtonClick);
        if(!actionContent){
            actionContent = [];
        }
        actionContent.push(anotherButton);
    }

    protected function onAnotherButtonClick(event:MouseEvent):void
    {
        trace("This is another button");            
    }

    override protected function partAdded(partName:String, instance:Object):void{
        super.partAdded(partName, instance);
        if(instance == myButton){
            myButton.addEventListener(MouseEvent.CLICK, onButtonClick);
        }
    }

    protected function onButtonClick(event:MouseEvent):void
    {
        trace("This is a simple button");           
    }
}

Skin File: 皮肤文件:

<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark">
<!-- host component -->
<fx:Metadata>
    [HostComponent("com.accessdigital.core.SimpleView")]
</fx:Metadata>

<!-- states -->
<s:states>
    <s:State name="disabled" />
    <s:State name="normal" />
</s:states>

<!-- SkinParts
name=myButton, type=spark.components.Button, required=true
name=contentGroup, type=spark.components.Group, required=false
-->
<s:Rect width="100%" height="100%">
    <s:fill>
        <s:LinearGradient rotation="90">
            <s:GradientEntry color="#666666"/>
            <s:GradientEntry color="#222222"/>
        </s:LinearGradient>
    </s:fill>
</s:Rect>
<s:Group id="contentGroup" width="100%" height="100%">
    <s:Button id="myButton" label="My Button" horizontalCenter="0" verticalCenter="0"/>
</s:Group>
</s:Skin>

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM