BlackBerry - MainScreen with labels vertical scroll - user-interface

I am trying to create a MainScreen with vertical scrolling. From what I've read in the documentation, MainScreen has a VerticalManager inside, so it should be possible to enable vertical scrolling only with proper construction, i.e:
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
This is not working for me, however. I am creating a screen, adding a couple of LabelFields and no scrollbar, no scrolling at all. I am testing on 8900, OS 5.0.
Here is the code I use:
public class ExampleScreen extends MainScreen {
public ExampleScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
create();
}
private void add(String text) {
add(new LabelField(text));
}
private void create() {
add("line 0");
add("line 1");
...
etc
...
}
}
The question is am I doing something wrong? Is there a way to enable vertical scrolling with MainScreen or do I need to create a VerticalManager myself?

The LabelField(s) added to the screen should either be FOCUSABLE themselves, or you can add the following BETWEEN each of the label fields: add(new NullField(NullField.FOCUSABLE));

Related

How to calculate position value (height) when scrolling item on ListView (Xamarin Forms)?

I'm building a layout like the main page of AppStore
This app has handled when the user scrolls ListView, SearchBar will gradually hide like the following GIF image:
How to calculate position value (height) when scrolling item on ListView (Xamarin Forms)?
Example: When I scroll an apart of an item on ListView, Layout contains Searchbar will hide an apart of it (layout contains SearchBar),
with height (an apart of item is scrolled on ListView) = height (an apart of SearchBar is hidden)
Please suggest me an idea and solution!
You have to use custom renderer to detect the value of height you scrolled, I wrote a simple example in iOS:
[assembly: ExportRenderer (typeof(myListView), typeof(MyListViewRenderer))]
namespace App556.iOS
{
public class MyListViewRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.ListView> e)
{
base.OnElementChanged(e);
Control.Delegate = new myDeleagte();
}
}
public class myDeleagte : UITableViewDelegate {
public override void Scrolled(UIScrollView scrollView)
{
Console.WriteLine(scrollView.ContentOffset.X);
Console.WriteLine(scrollView.ContentOffset.Y);
}
}
}
Handle your event in the Scrolled method or use messaging-center to handle event in Xamarin.forms.Project.
ListView only has itemappearing method for you to do something when scrolling, you can have a look at it.

Frame goes transparent on tap

I am working on a Xamarin.Forms project with a ListView and each item has a Frame with a white background. My problem is I recently noticed when I tap the Item it makes the Frame's background white. It still shows all the other objects but the frame goes transparent.
The frame is simply
<Frame CornerRadius="10" Padding="0" Margin="10, 10, 10, 5" BackgroundColor="White">...</Frame>
Promoting above comments-answer to real-answer for readability sake:
The behavior you are seeing is specific to iOS. You can solve it by overriding the default behavior using an effect, like so:
[assembly: ResolutionGroupName("MyEffects")]
[assembly: ExportEffect(typeof(ListViewHighlightEffect), nameof(ListViewHighlightEffect))]
namespace MyProject.iOS.Effects
{
public class ListViewHighlightEffect : PlatformEffect
{
protected override void OnAttached()
{
var listView = (UIKit.UITableView)Control;
listView.AllowsSelection = false;
}
protected override void OnDetached()
{
}
}
}
Then, you can apply it in your view code-behind:
MyListView.Effects.Add(Effect.Resolve($"MyEffects.ListViewHighlightEffect"));
I did a short write-up on the full solution here
Alternatively, if you want to maintain the ability to select an item, one possible fix would be to add an ItemTapped handler in your code behind and null out
MyListView.SelectedItem = null;

Unity Slider doesn't apply changes automatically

I've created custom Editor with Slider:
[CustomEditor(typeof(CylindricalCamera))]
public class CylindricalCameraEditor : Editor
{
public override void OnInspectorGUI()
{
CylindricalCamera camera = (CylindricalCamera)target;
camera._nearClipPlane = EditorGUILayout.Slider(camera._nearClipPlane, 0, 10);
In CylindricalCamera I am drawing a custom gizmo:
public class CylindricalCamera : MonoBehaviour
{
..
void OnDrawGizmos()
{
...
I want a gizmo in CylindricalCamera to be repainted every time I drag the slider. But in fact I have not only to drag the slider, but also to select and press Enter on the textbox near the Slider:
Custom slider
How could I force Slider to apply changes automatically, without pressing Enter?
I am using Unity 5.3.5 f1
Solved:
OnInspectorGUI()
{
...
if (GUI.changed) EditorUtility.SetDirty(target);
}

How to remove the border or border colour of the SearchBar?

I am new to Xamarin.forms. I am using a SearchBar followed by a BoxView.
The problem that I am facing is removing the border line of the SearchBar.
This border makes the UI appear as if there is a separator in between the SearchBar and the BoxView.
Any help in achieving this is much appreciated.
Thanks much :)
Think you might need a custom renderer for this like so:
using MonoTouch.UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly:ExportRenderer( typeof(NamespaceOfApp.MySearchBar), typeof(NamespaceOfApp.iOS.SearchBarWithNoBarRenderer_iOS))]
namespace NamespaceOfApp.iOS
{
public class SearchBarWithNoBarRenderer_iOS : SearchBarRenderer
{
protected override void OnElementChanged( ElementChangedEventArgs<SearchBar> args )
{
base.OnElementChanged( args );
UISearchBar bar = (UISearchBar)this.Control;
//set background to empty image
bar.SetBackgroundImage (new UIImage (), UIBarPosition.TopAttached, UIBarMetrics.Default);
}
}
}
If you need a hand with custom renderers look here
Effects was introduced in Forms v2 as the recommended way to extending the Forms base controls. https://developer.xamarin.com/guides/xamarin-forms/effects/
For example; this would be your iOS Effect code...
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly:ResolutionGroupName ("MyCompany")]
[assembly:ExportEffect (typeof(FocusEffect), "FocusEffect")]
namespace EffectsDemo.iOS
{
public class FocusEffect : PlatformEffect
{
protected override void OnAttached ()
{
// your code here
}
protected override void OnDetached ()
{
// your code here
}
protected override void OnElementPropertyChanged (PropertyChangedEventArgs args)
{
base.OnElementPropertyChanged (args);
// your code here
}
}
}
Custom Renderers were the only option in Forms v1.x. Custom Renderers are great for building controls from scratch but it was a bit hit and miss when extending the built-in controls.
Using StoryBoard:
Using code:
public override void ViewWillLayoutSubviews ()
{
base.ViewWillLayoutSubviews ();
sampleSearchBar.SearchBarStyle = UISearchBarStyle.Minimal;
sampleSearchBar.BarTintColor = UIColor.Clear;
}

Text and Image on SWT Button

Is there a way to have a SWT buuton with both image and text in a view? I have tried embedding Swings in SWT and the view looks exactly as I want, but when there is an operation going on, this view doesnot load till it gets over. This makes my perspective look unstable. Please help.
What OS are you using? On Windows XP/Vista/Windows 7, GTK+ and OSX you can just set the text and the image. E.g.
public class ButtonView extends ViewPart
{
private Button m_button;
public void createPartControl(Composite parent)
{
m_button = new Button(parent, SWT.NONE);
m_button.setText("My Button");
m_button.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR));
}
public void setFocus()
{
m_button.setFocus();
}
}

Resources