Titanium Android Horizontal & Vertical Scroll - titanium

Titanium appcelerator while scrolling horizontally, ui is scrolling vertically. Is there anyway to lock vertical scrolling while horizontal scrolling ?

For horizontal scrolling:
<Alloy>
<Window backgroundColor="white">
<ScrollView backgroundColor="gray" layout="horizontal" width="Ti.UI.FILL" height="Ti.UI.SIZE" scrollType="horizontal">
<View left="10" width="100" height="100" backgroundColor="red" />
<View left="10" width="100" height="100" backgroundColor="red" />
<View left="10" width="100" height="100" backgroundColor="red" />
<View left="10" width="100" height="100" backgroundColor="red" />
<View left="10" width="100" height="100" backgroundColor="red" />
<View left="10" width="100" height="100" backgroundColor="red" />
<View left="10" width="100" height="100" backgroundColor="red" />
<View left="10" width="100" height="100" backgroundColor="red" />
<View left="10" width="100" height="100" backgroundColor="red" />
</ScrollView>
</Window>
</Alloy>
For vertical scrolling:
<Alloy>
<Window backgroundColor="white">
<ScrollView backgroundColor="gray" layout="vertical" width="Ti.UI.SIZE" height="Ti.UI.FILL" scrollType="vertical">
<View top="10" width="100" height="100" backgroundColor="red" />
<View top="10" width="100" height="100" backgroundColor="red" />
<View top="10" width="100" height="100" backgroundColor="red" />
<View top="10" width="100" height="100" backgroundColor="red" />
<View top="10" width="100" height="100" backgroundColor="red" />
<View top="10" width="100" height="100" backgroundColor="red" />
<View top="10" width="100" height="100" backgroundColor="red" />
<View top="10" width="100" height="100" backgroundColor="red" />
<View top="10" width="100" height="100" backgroundColor="red" />
</ScrollView>
</Window>
</Alloy>
Titanium Classic Example
var win = Ti.UI.createWindow({
backgroundColor : 'white'
});
var scrollview = Ti.UI.createScrollView({
backgroundColor : "gray",
layout : "horizontal",
width : Ti.UI.FILL,
height : Ti.UI.SIZE,
scrollType : "horizontal"
});
for (var i=0; i<=10; i++) {
scrollview.add(createView());
}
win.add(scrollview);
win.open();
function createView() {
return Ti.UI.createView({
backgroundColor : 'red',
width : 100,
height : 100,
left : 10
});
}
Your keypoint to restrict the scroll direction on Android is scrollType property.

Related

Frame size not applying? - XAML MAUI

I am trying to make a frame a specific size but the frame seems to only match the size with components inside of the frame.
I tried finding solutions but couldn't find anything, perhaps I am searching for the wrong things.
The XAML:
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Frame BackgroundColor="#303030"
Padding="8" CornerRadius="5"
HeightRequest="500" WidthRequest="500">
<StackLayout Spacing="10">
<Label Text="Login" FontSize="Medium" FontAttributes="Bold" />
<BoxView Color="{DynamicResource Primary}" HeightRequest="2" HorizontalOptions="Fill" />
<Entry Placeholder="Username" />
<Entry Placeholder="Password" IsPassword="True" />
<Button Text="Login" BackgroundColor="{DynamicResource Primary}" TextColor="{DynamicResource White}" />
</StackLayout>
</Frame>
</VerticalStackLayout>
</ScrollView>
What it looks like:
What I want it to look like:
View toolmakersteve's response if you have this "issue" too!
Code:
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center"
WidthRequest="400"
HeightRequest="400">
<Border BackgroundColor="#303030"
Padding="8">
<StackLayout Spacing="10">
<Label Text="Login" FontSize="Medium" FontAttributes="Bold" />
<BoxView Color="{DynamicResource Primary}" HeightRequest="2" HorizontalOptions="Fill" />
<Entry Placeholder="Username" />
<Entry Placeholder="Password" IsPassword="True" />
<Button Text="Login" BackgroundColor="{DynamicResource Primary}" TextColor="{DynamicResource White}" Clicked="LoginClick" />
</StackLayout>
</Border>
</VerticalStackLayout>
</ScrollView>
Result:

System.TypeInitializationException Xamarin CarouselView

The type initializer for 'Xamarin.Forms.ItemsView' threw an exception. After click button.
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'Xamarin.Forms.ItemsView' threw an exception. occurred
`<CarouselView>
<CarouselView.ItemsSource>
<x:Array Type="{x:Type View}">
<ContentView>
<Image Source="yuzon.jpg"/>
</ContentView>
<ContentView>
<Image Source="yuzyirmi.jpg"/>
</ContentView>
<ContentView>
<Image Source="yuzkirks.jpg" />
</ContentView>
<Image Source="yuzelli.jpg" />
<ContentView>
<Image Source="yuzaltmis.jpg" />
</ContentView>
<ContentView>
<Image Source="ikiyuzyirmi.jpg"/>
</ContentView>
<ContentView>
<Image Source="ikiyuzkirkC.jpg" />
</ContentView>
<ContentView>
<Image Source="ikiyuzyetmis.jpg" />
</ContentView>
<Image Source="ucyuz.jpg" />
<ContentView>
<Image Source="ucyuzF.jpg" />
</ContentView>
<ContentView>
<Image Source="ucyuzon.jpg" />
</ContentView>
<ContentView>
<Image Source="ucyuzotuz.jpg" />
</ContentView>
<ContentView>
<Image Source="ucyuzaltmis.jpg" />
</ContentView>
</x:Array>
</CarouselView.ItemsSource>
</CarouselView>`
This control belongs to Xamarin.Forms 4.0. So you have to update your forms version to 4.0 to test this new feature.
Moreover, you have to add
global::Xamarin.Forms.Forms.SetFlags("CollectionView_Experimental"); in your MainActivity.cs and AppDelegate to enable this testing.
Unfortunately, Carousel View can be only used on Android: https://github.com/pauldipietro/CollectionViewSample.
Follow this blog to learn more concepts: https://devblogs.microsoft.com/xamarin/xamarin-forms-4-0-feature-preview-an-entirely-new-point-of-collectionview/

Stretch my buttons in a TopAppBar

I am developing a universal application in Visual Studio 2015 Community, but I have a problem in stretching my 3 buttons when I test my application on local PC or the Windows phone emulator, this is what I get with my code:
<CommandBar Height="51" >
<CommandBar.Content>
<Grid>
<StackPanel>
<Image x:Name="image1" Margin="41,10,-168,-50" Source="images/name.png" RenderTransformOrigin="0.487,0.82"/>
<Image x:Name="image" Margin="1,0,-40,-50" Source="images/icon.png"/>
</StackPanel>
<StackPanel>
<Button Height="49" Margin="0,0,-244,0" Width="35" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<Button.Content>
<Image Source="images/home.png" Margin="-9,0.333,-9,-0.667"/>
</Button.Content>
</Button>
</StackPanel>
<StackPanel>
<Button Height="49" Margin="0,0,-280,0" Width="35" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<Image Source="images/search.png" Margin="-9,0.333,-9,-0.667"/>
</Button>
</StackPanel>
<StackPanel>
<Button Height="49" Margin="0,0,-315,0" Width="35" HorizontalAlignment="Right" VerticalAlignment="Stretch">
<Image Source="images/profil.png" Margin="-9,0.333,-9,-0.667"/>
</Button>
</StackPanel>
</Grid>
</CommandBar.Content>
This what I want to get:
This is going to get you there:
<!--Content Alignment is left by default!-->
<CommandBar HorizontalContentAlignment="Stretch">
<CommandBar.Content>
<Grid>
<!--Left element-->
<Rectangle Margin="10" Height="35" Width="35" Fill="Red"
HorizontalAlignment="Left"/>
<!--Right elements together in a horizontal StackPanel-->
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Right">
<Rectangle Margin="10" Height="35" Width="35" Fill="Red" />
<Rectangle Margin="10" Height="35" Width="35" Fill="Red" />
<Rectangle Margin="10" Height="35" Width="35" Fill="Red" />
</StackPanel>
</Grid>
</CommandBar.Content>
</CommandBar>
First up, you tagged your question inside several different area's, so it's difficult for us to tell what platform you are on. Is it a WinRT 8.1 app or a UWP windows 10 app?
But for reference, if it's a UWP Win10 app, first try to use following XAML, it creates a CommandBar with 1 primary command. And on the UWP platform that will position the icon at the right of the screen.
<CommandBar IsOpen="True" IsSticky="True">
<CommandBar.PrimaryCommands>
<AppBarButton Icon="Add" />
</CommandBar.PrimaryCommands>
</CommandBar>
More info on what and how items are displayed inside a commandbar can be found on MSDN here https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.commandbar.aspx
There are a few issues with what you're trying.
The XAML you have is more complicated than it needs to be.
You've tried to align controls by setting margins - this doesn't work with
variable sized containers.
You're not using any of the functionality of the CommandBar so you probably don't need it.
Instead you can make the layout you desire with a simple grid.:
<Grid VerticalAlignment="Top" Height="51">
<StackPanel HorizontalAlignment="Left">
<Image x:Name="image1" Source="images/name.png" />
<Image x:Name="image" Source="images/icon.png"/>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
<Button >
<Image Source="images/home.png" />
</Button>
<Button>
<Image Source="images/search.png" />
</Button>
<Button >
<Image Source="images/profil.png" />
</Button>
</StackPanel>
</Grid>

How to display a loading message in Xamarin.Forms

I am new to Xamarin.Forms in which I need loading message. How can I display the loading message?
Code:
<AbsoluteLayout>
<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" AbsoluteLayout.LayoutBounds="0, 0, 1, 1"
AbsoluteLayout.LayoutFlags="All" Padding="30" >
<Grid>
//something
</Grid>
</StackLayout>
<ContentView x:Name="overlay" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All" IsVisible="False" BackgroundColor="#C0808080" Padding="10, 0">
<ActivityIndicator WidthRequest="110" HeightRequest="70" IsRunning="True" IsVisible="True" Color="Black" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</ContentView>
</AbsoluteLayout>
Set IsVisible="True" for ContentView will show you the ActivityIndicator.
<ContentView x:Name="overlay" AbsoluteLayout.LayoutBounds="0, 0, 1, 1" AbsoluteLayout.LayoutFlags="All" IsVisible="True" BackgroundColor="#C0808080" Padding="10, 0">
<ActivityIndicator WidthRequest="110" HeightRequest="70" IsRunning="True" IsVisible="True" Color="Black" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"/>
</ContentView>
If you are using MVVM and want full modal Loading Messages look at ACR User Dialogs for Xamarin and Windows. You can install it via nuget. You can find the sample application here.

Why a button with an image doesn't respect width and height settings

I'm creating a button that will display an image instead of text, the problem is, the width and height is just ignored.
Why?
<Button Grid.Column="1" Grid.Row="1" Width="60" Height="60" Margin="0, -30, 0, 0" BorderThickness="0" >
<Image Source="Assets/ic_play.png" Width="60" Height="60" Margin="0,-29, 0,0" />
</Button>
Button has MinWidth/MinHeight property by default (see question here. The Style of the default button looks like in this answer.
So you will have to override those minimum values for single button (or define Style and use it among other buttons):
<Button Grid.Column="1" Grid.Row="1" MinHeight="60" MinWidth="60" Width="60" Height="60" Margin="0, -30, 0, 0" BorderThickness="0" >
<Image Source="Assets/ic_play.png" Width="60" Height="60" Margin="0,-29, 0,0" />
</Button>