Populate ScrollView Dynamically with ImageView - imageview

I'm new in using Titanium. I tried to load some images into a scrollview. But only one image is loading into the scrollview area. Codes are here
XML
<Alloy>
<Window class="container">
<ScrollView showHorizontalScrollIndicator="true" id="Scroll" layout="horizontal">
</ScrollView>
</Window>
</Alloy>
JS
var scrollView = $.Scroll;
var URLs = ["http://static.flickr.com/41/81743961_588dafe12d_o_d.jpg", "http://static.flickr.com/26/64914466_eed02e2a71_o_d.jpg"];
var Views = [];
for (i =0; i < URLs.length ; i++){
Views.push(Ti.UI.createImageView({
image : URLs[i],
width : Ti.UI.SIZE,
height : 300,
top : 0,
left : 0,
})
);
}
Views.forEach(function(view){
scrollView.add(view);
});
$.index.open();
TSS
".container": {
backgroundColor:"white"
},
"#Scroll":{
width:Ti.UI.SIZE,
top: 50,
}
Screenshot
I need your help to find out my mistake.
Thanks

Its in your XML file :
<Alloy>
<Window class="container">
<ScrollView showHorizontalScrollIndicator="true" id="Scroll" layout="horizontal">
</ScrollView>
</Window>
you have set the layout to horizontal, If you will scroll horizontally you will find your second Image there.
Or you can change
horizontal to vertical
The Image will appear below the first Image.
checkout the docs.
Hope it helps.

Related

How to set a background image to a Grid in xamarin.forms?

I want to set a background image to my Grid in code behind. I found in internet that we can do using XAML like this.
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Pages.PhotoPage">
<Grid >
<Image Source="background.png" Aspect="AspectFit" />
<!-- Place here the rest of the layout for the page. -->
</Grid >
But how can I set this in code behind. I cannot see anyImage or BackgroundImage property for Grid. Please help me.
Thanks
You can just create an empty Image element in the Grid and set it.
<Grid>
<Image x:Name="BackgroundImage" Aspect="AspectFit" />
<!-- Place here the rest of the layout for the page. -->
</Grid>
And now set it in code:
backgroundImage.Source = ...;
If you are building the whole UI in code, you can do this as well:
var myGrid = new Grid();
var backgroundImage = new Image();
backgroundImage.Source = ...;
myGrid.Children.Add( backgroundImage );
If your Grid has multiple rows and columns, you will want to set the Grid.ColumnSpan and Grid.RowSpan properties on the image to make it span the whole grid.

Remove white space at bottom of page xamarin.forms

I have this Xamain.Forms app where I hide page title when the device orientation changes. It all works fine but on Android a white space is showing above the content when I switch to horizontal view. You can see how it looks in the pictures below.
enter image description here
enter image description here
This is my xaml code:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Kanal10Live.VideoTest">
<ContentPage.Content>
<StackLayout x:Name="VideoStack">
<WebView x:Name="Browser" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"></WebView>
</StackLayout>
</ContentPage.Content>
And this is code behind:
private double width = 0;
private double height = 0;
protected override void OnSizeAllocated(double width, double height)
{
base.OnSizeAllocated(width, height);
switch (Device.RuntimePlatform)
{
case Device.Android:
if (width != this.width || height != this.height)
{
this.width = width;
this.height = height;
if (width > height)
{
NavigationPage.SetHasNavigationBar(this, false);
VideoStack.Orientation = StackOrientation.Horizontal;
}
else
{
NavigationPage.SetHasNavigationBar(this, true);
VideoStack.Orientation = StackOrientation.Vertical;
}
}
break;
}
}
The funny thing is that if I use the below code when the page initializes all is fine.
If someone can help me I would be grateful!
Peter
Try:
<Grid>
<WebView x:Name="Browser" />
</Grid>
Grid by default fills the full page. If you don't set any horizontal or vertical options on the web view it should fill the whole grid.

How can i scroll bottom on onPress of button in react-native?

I have added the button on simple screen and I want to scroll Bottom whenever I press the button. what code to add to button onPress?
render() {
return (
<ScrollView>
{this.yourComponents()}
<Button>Scroll To Bottom </Button>
</ScrollView>
)
}
You could do this using ref.
render() {
return (
<ScrollView ref={scrollView => this.scrollView = scrollView}>
{this.yourComponents()}
<Button onPress={() => {this.scrollView.scrollToEnd()}}>Scroll To Bottom </Button>
</ScrollView>
)
}
You can also do this using the useRef hook.
const scrollView = useRef();
const scrollView = useRef();
const onPress = () => {
scrollView.current.scrollToEnd();
}
<Button onPress={onPress} />
This question is quite similar to this one but isn't exactly the same, that is why i'll provide an answer.
ScrollView provide a ScrollTo() method that allows you to scroll to a x/y position in your scrollview.
let _scrollViewBottom
<ScrollView
ref='_scrollView'
onContentSizeChange={(contentWidth, contentHeight)=>{
_scrollViewBottom = contentHeight;
}}>
</ScrollView>
then use the ref name of the scroll view like
this.refs._scrollView.scrollTo(_scrollViewBottom);
Additionally, if your goal is to frequently push new data and scroll at the end of your scrollview, you might wanna take a look at react-native-invertible-scroll-view.
InvertibleScrollView is a React Native scroll view that can be inverted so that content is rendered starting from the bottom, and the user must scroll down to reveal more. This is a common design in chat applications
For functional component
<ScrollView
ref={ref => { scrollView = ref }}
onContentSizeChange={() => scrollView.scrollToEnd({ animated: true })}
>
...
</ScrollView>
For class component
<ScrollView
ref={ref => { this.scrollView = ref }}
onContentSizeCange={() => this.scrollView.scrollToEnd({ animated: true })}
>
...
</ScrollView>
let _scrollViewBottom
<ScrollView
ref={scrollViewRef}
onContentSizeChange={(contentWidth, contentHeight)=>{
_scrollViewBottom = contentHeight;
// this make move your scroll
scrollViewRef.current.scrollTo({x:0,y:_scrollViewBottom ,animated:true});
}}>
</ScrollView>
Additionally, if your goal is to frequently push new data and scroll at the end of your scrollview, you might wanna take a look at react-native-invertible-scroll-view.
InvertibleScrollView is a React Native scroll view that can be inverted so that content is rendered starting from the bottom, and the user must scroll down to reveal more. This is a common design in chat applications

ScrollOrientation.Both on Xamarin Forms ScrollView

Does anyone have any suggestions to allow a ScrollView to allow scrolling in any direction.
There seems to be only Horizontal & Vertical ScrollOrientation but no option to do both at the same time.
My end goal is to be able to pinch, zoom & scroll any direction.
Xamarin Forms scrollview's Orientation property now accepts Both as a value. It scrolls on both direction. I am using Xamarin Forms version 2.3.0.49.
<ScrollView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Orientation="Both">
Here's how you do it.
var scroller = new ScrollView { Content = grid, Orientation= ScrollOrientation.Horizontal, VerticalOptions=LayoutOptions.FillAndExpand };
var vScroller = new ScrollView (){Content=scroller};
Content = vScroller;
ScrollOrientation is not a [Flags] enum and does not contains Both value, so this i snot supported at this time. But this could work:
new ScrollView {
Orientation = ScrollOrientation.Vertical,
Content = new ScrollView {
Orientation = ScrollOrientation.Horizontal,
Content = your_content_goes_here,
}
}

How to display button over a map / MapLayer in windows phone 8?

I'm new in Windows phone 8 development and I have problem to add button on MapLayer.
I'd like to display a button over a map so I just draw it on the map widget like this:
<Grid x:Name="MyMapGrid" Margin="10,-15,15,0" VerticalAlignment="Top" Height="296" >
<maps:Map x:Name="MyMapi" Center="31.765537,35.106812" ZoomLevel="7" Margin="0,0,0,0" VerticalAlignment="Top" Height="296" Width="442" />
<Button x:Name="myCustomButton" Visibility="Visible" Content="" HorizontalAlignment="Left" Margin="347,0,0,0" VerticalAlignment="Top" Width="84" Height="84" BorderThickness="0">
<Button.Background>
<ImageBrush ImageSource="/myZoom.png"/>
</Button.Background>
</Button>
</Grid>
After this action I need to put some icons on the map so I used MapOverlay and MapLayer like this:
Map MyMap = new Map();
MapOverlay overlay = new MapOverlay
{
GeoCoordinate = MyMap.Center,
Content = new Image()
{
Source = new BitmapImage(new Uri("customIcon.png", UriKind.Relative)),
}
};
MapLayer layer = new MapLayer();
layer.Add(overlay);
MyMap.Layers.Add(layer);
MyMapGrid.Children.Add(MyMap);
I also need my button (myCustomButton) will stay visible - but it disappear.
how can I still have some button over the map and also view some icons on it?
Thank you all!
For button Change the path to definite like ImageSource="/Assets/Icon/location.png" with the folder name and make sure that BuildAction is set to content for that image
For icon also try the same.

Resources