I'm trying to use Animate in MXML to move a button along X or Y axis.
My button increase width when clicked, but does not move at all. What is wrong with this code ? It should be something really simple, but I can't find it.
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark"
initialize='init()'>
<fx:Script>
<![CDATA[
public function init():void {}
]]>
</fx:Script>
<s:layout>
<s:VerticalLayout id='l' horizontalAlign="left" />
</s:layout>
<fx:Declarations>
<s:Animate id="mover" target="{button}" duration="1000">
<s:SimpleMotionPath property="x" valueFrom="0" valueTo="100"/>
<s:SimpleMotionPath property="y" valueTo="100"/>
<s:SimpleMotionPath property="width" valueBy="20"/>
</s:Animate>
</fx:Declarations>
<s:Button id="button" click="mover.play()" label="Button"/>
</s:Application>
I got this sample from Adobe docs. I think it should be related to layout or something like that, but all my tries of changing layout, including into a Canvas or other tricks does not change anything : the button still stay at the same place.
Thanks for your help !
The problem is caused by the use of the VerticalLayout. This layout, as well as the HorizontalLayout, ignores x/y properties of the objects that are being laid out.
If you remove your layout declaration altogether, it will then use the default BasicLayout which will honor the x/y properties and allow your animation to work.
Related
I'm using an AdvancedDataGrid that uses a groupIconFunction to return the icon near the arrow (top level tree) as a custom Image.
<?xml version="1.0" encoding="utf-8"?>
<mx:AdvancedDataGrid xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
lockedColumnCount="4"
groupIconFunction="getGroupIcon">
in the <fx:Script>:
[Embed(source="/images/customTreeNodeImg.png")]
[Bindable] public var nodeImg:Class;
protected function getGroupIcon(item:Object, depth:int):Class {
return nodeImg;
}
The issue here is that the Image is blurry. I sense I need to scale the Class down, or some other way I can make the Image clear?
If I double the size of customTreeNodeImg.png, the image size is doubled, and still blurry. The default folder is clear.
How would I go about making my custom Image of the icon display clearly in Retina?
Solution: Import the original svg into Illustrator and scale it to the size needed in Illustrator, then Export to swf.
Then import into Flex:
Embed(source="/images/customTreeNodeImg.swf")] // <--- swf / vector
[Bindable] public var nodeImg:Class;
I have been endeavouring to implement 3D shapes in JavaFX using fxml, but have encountered difficulty in specifying the static predefined colors in the Color class on a PhongMaterial.
As an example, a code snippet for a Box object is:
<Box fx:id="box" width="100" height="200" depth="300">
<material>
<PhongMaterial >
</PhongMaterial>
</material>
</Box>
If anybody can please tell me how to specify the required color attribute on this object it will be much appreciated.
It was as simple as including a diffuseColor attribute in the PhongMaterial tag,
<PhongMaterial diffuseColor="GREEN" />
whereas I had originally attempted to include a nested diffuseColor tag between the PhongMaterial tags.
I Want to Create a List View with a Custom layout which will contain A image and text
But all the tutorials i find all extend List Activity but i cant extend List Activity because i need to add buttons and other things to the layout.
I need to use the ListView using a custom item layout
any ideas on how to do it?
You are not bound to use ListActivity in order to have a ListView in your layout. All the samples using ListActivity are there because people are lazy ;)
So just use a regular Activity and then you simply have to add the ListView to the layout you are setting as content view. This could look something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="0"
android:layout_weight="1" />
<Button
android:id="#+id/somethingButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Do something" />
<Button
android:id="#+id/elseButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Do something else" />
</LinearLayout>
Then in like any other Activity in your OnCreate method you do:
SetContentView(Resource.Layout.myLayout); // myLayout.axml
var listView = FindViewById<ListView>(Resource.Id.listView);
listView.Adapter = new MyAdapter(context, itemsSource);
var somethingButton = FindViewById<Button>(Resource.Id.somethingButton);
var elseButton = FindViewById<Button>(Resource.Id.elseButton);
... more code ...
ListView is just a layout just like any other, so there is nothing magic about it. MyAdapter in this sample is ofcourse something you implement, which takes your data and presents it in the desired image and text layout.
For more information about ListView and Adapter please refer to the excellent documentation which Xamarin provides.
I am trying adopt the v21 AppCompat libraries and leverage the better control of the ActionBar using a Toolbar as described here and here. But no matter how I modify the menu XML, I can only get the menu items to show up in the overflow area. I would like to see the MenuItem represented as an icon on the Toolbar/ActionBar.
My menu declaration looks like this (note the showAsAction line):
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res-auto="http:/>/schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item android:id="#+id/action_add"
android:icon="#android:drawable/ic_menu_add"
android:title="#string/action_add"
android:orderInCategory="2"
res-auto:showAsAction="always" />
</menu>
I have also tried this (with a slightly different showAsAction line):
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res-auto="http:/>/schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity" >
<item android:id="#+id/action_add"
android:icon="#android:drawable/ic_menu_add"
android:title="#string/action_add"
android:orderInCategory="2"
android:showAsAction="always" />
</menu>
But the only way I have successfully been able to get the icon to show up on the Toolbar/ActionBar is to force it in code.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
// Try to manually force the item onto the bar instead of allowing it in the overflow
// for some reason, android is not picking up the setting in the menu declaration
// using android:showAsAction="always" (even when using the auto-res namespace)
MenuItem addItem = menu.findItem(R.id.action_add);
MenuCompat.setShowAsAction(addItem, MenuItem.SHOW_AS_ACTION_ALWAYS);
return true;
}
I am using the android.support.v4.view.MenuCompat static methods to achieve this. But I believe I should be able to do this declaratively in the XML. I have tried using both "always" and "ifRoom" but for no effect. I can only assume that the XML attribute is not being picked up.
I guess it is really something simple or related to the fact that I am using the new Toolbar to function as the holder of the menu. The Toolbar layout is very simple:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
and the usage seems quite standard:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Any help would be appreciated. And I am happy to share more of the project content if it helps to get to the bottom of it.
Take the following code snippet:
<View id='container'>
<View id='child' width=100 height=100/>
<View id='child1' width=100 height=100/>
<View id='child2' width=100 height=100 />
<View id='child3'width=100 height=100 visible='false' bottom='0'/>
</View>
I have a container and nested in it, child views.
Say I make child 3 visible false, the problem is the window will not resize accordingly and there will be white space for where child 3 is. As it is rendered, but hidden.
How can I deal with white space in titanium.
Thanks
I have also faced this problem. I simply set height property to 0 instead of making view invisible.
You can add that element later after the window is created using the js.Just change the code to add the view instead of making it visible.
something like this :
$.container.add(child3);
Hope it helps.