Xamarin.Forms Layout Challenges – Great Places(已全文翻译)

原文地址:https://www.kymphillpotts.com/xamarin-forms-layout-challenges-great-places/ (作者Kym Phillpotts)

项目Github地址:https://github.com/kphillpotts/XamarinFormsLayoutChallenges

When your app is all about the images, sometimes you want your images to be hero of the UI.  That’s what this weeks Xamarin.Forms Layout Challenge is all about.    Normally I prefer a light themed application, so just to change things up a bit, I thought I would go for a dark themed layout. They say, variety is the spice of life.

当你的app充满了图片,你有时想让你的图片成为UI的主角. 这周的Xamarin.Forms 布局挑战就是关于此的.我通常更喜欢主题是明亮的app,为了改变这一点,我觉得我应该试试黑暗主题的布局.他们说,丰富多彩是生活的情趣所在.

Page Layout

The page layout, not surprisingly is really just a ListView.  I played around with adding a bit of spice by making the ListView have a transparent background and put a purple gradient behind the ListView.  I’m not sure it’s great, but kind of interesting, none-the-less.

页面布局,没什么可惊喜的,真的只有ListView. 通过让ListView的BackGround透明,把紫色渐变图片放在ListView的后面. 我不确定这样做很棒,但是至少很有趣.

    <Grid>
    <Image Source="ColoredBackground" VerticalOptions="Fill" HorizontalOptions="Fill" Aspect="Fill"/>
    <ListView x:Name="placeList"
        BackgroundColor="Transparent"
        RowHeight="200" ItemsSource="{Binding .}" SeparatorVisibility="None">

The ViewCell

The ViewCell is pretty straight forward.  The whole cell is a Grid of 2 rows.

The “Hero Image” spans both the rows.  At the bottom, I included a slight “Transparent to Black” overlay that helps the text to be more readable at the bottom

ViewCell真的很简单,整个Cell只有一个包含两行的Grid。Hero Image占了两行。在底部,我设置了一个从透明到黑色的图片去覆盖原有的图片,这样做是为了让底部的文字更容易被阅读.

<Grid RowSpacing="5" ColumnSpacing="0" Margin="10,5" >
  <Grid.RowDefinitions>
    <RowDefinition Height="*"/>
    <RowDefinition Height="AUTO"/>
  </Grid.RowDefinitions>

  <Image Source="{Binding HeroImage}" Aspect="AspectFill" Grid.RowSpan="2" />
  <Image Source="ShadowOverlay" Grid.RowSpan="2"  Aspect="Fill" VerticalOptions="End" HorizontalOptions="Fill" />

The text parts are  done with a Grid that occupies the 2nd row

文字部分,是一个位于Grid的第二行的Grid.

<Grid Margin="10" RowSpacing="10" ColumnSpacing="10" Grid.Row="1">
  <Grid.RowDefinitions>
    <RowDefinition Height="AUTO"/>
    <RowDefinition Height="25"/>
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="25"/>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="AUTO"/>
  </Grid.ColumnDefinitions>

  <Label Text="{Binding Title}"  Grid.Row="0" Grid.ColumnSpan="3" Style="{StaticResource TitleLabel}" LineBreakMode="NoWrap"/>

  <controls:CircleImage Source="{Binding ProfileImage}" Aspect="AspectFill" Grid.Row="1" Grid.Column="0" WidthRequest="25" HeightRequest="25" />

  <Label Text="{Binding Handle}" Grid.Row="1" Grid.Column="1" VerticalOptions="Center" Style="{StaticResource HandleLabel}" />

  <StackLayout Orientation="Horizontal"  VerticalOptions="Center" Grid.Column="2" Grid.Row="1" Spacing="5">
    <Image Source="Eye"/>
    <Label Text="{Binding ViewCount, StringFormat=‘{0:N0}‘}" Style="{StaticResource HandleLabel}" />
    <Label Text="views" Style="{StaticResource BodyLabel}"/>
  </StackLayout>

</Grid>

You’ll notice that I have used the CircleImage plugin from James Montemagno.  It just requires a little reference to the namespace at the top of the page:

你会注意到,我是用了CircleImage 插件,在Page的顶部需要写明 命名空间的引用.

xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin.Abstractions"

Also for the viewcount, I added a little bit of string formatting, which is a nice little binding feature, to show the comma’s in the ViewCount.

在ViewCount,我添加了一点string formatting,是绑定的一部分,用来展示逗号.

<Label Text="{Binding ViewCount, StringFormat=‘{0:N0}‘}" Style="{StaticResource HandleLabel}" />

How does it scale

It even doesn’t look too bad in landscape…

在风景图上面的表现也相当不错.

Wrap Up

So that is it, a simple image ListView.

I thought I should also mention a couple of places I go to get nice images for mockups

  • For random user data and images you can go to RandomUser.me
  • For some really nice royalty free images you can use Unsplash.com

As always, and you can grab the project over at https://github.com/kphillpotts/XamarinFormsLayoutChallenges

Also, make sure you check out some of the other layouts in Xamarin.Forms Layout Challenges.

Happy Layouts!

时间: 2024-08-01 14:11:16

Xamarin.Forms Layout Challenges – Great Places(已全文翻译)的相关文章

Xamarin.Forms Layout Challenges – Social Network App(转载)

Xamarin.Forms Layout Challenges – Social Network App(转载) 布局示例(一) 原文链接:http://www.kymphillpotts.com/social-network-app-layout-design-in-xamarin-forms/ GitHub链接:https://github.com/kphillpotts/XamarinFormsLayoutChallenges Youtube视频(英文)在这里:https://www.yo

Xamarin Forms error MSB6006: “java.exe”已退出,代码为 2 解决办法

https://vicenteguzman.mx/2017/08/20/error-java-exe-exited-with-code-2-xamari-forms/ 原文地址:https://www.cnblogs.com/mschen/p/9525209.html

搞懂Xamarin.Forms布局,看这篇应该就够了吧

Xamarin.Forms 布局介绍 什么是布局?可以简单的理解为,我们通过将布局元素有效的组织起来,让屏幕变成我们想要的样子! 我们通过画图的方式来描述一下Xamarin.Forms的布局. 小节锚点: 布局控件之StackLayout Xamarin.Forms 中可以C#代码进行布局 Xamarin.Forms 的布局方向 边距和填充 八种布局选项 布局控件之Grid 布局控件之AbsoluteLayout 布局控件之ScrollView 布局控件之RelativeLayout 布局控件之

Xamarin.Forms入门-使用 Xamarin.Forms 来创建跨平台的用户界面

Xamarin.Forms 是一个跨平台的.基于原生控件的UI工具包,开发人员可以轻松的创建适用于 Android,iOS 以及 Windows Phone的用户界面.Xamarin.Forms 通过使用平台的原生控件来渲染用户界面,使用 Xamarin.Forms 的 App在外观上与平台完全一致.通过本文您可以快速了解如何使用 Xamarin.Form 来进行应用程序的开发. 简介 Xamarin.Forms可以帮助开发人员快速的构建跨平台的UI,通过一次编码,生成多平台界面.如果你做的工作

张高兴的 Xamarin.Forms 开发笔记:Android 快捷方式 Shortcut 应用

一.Shortcut 简介 Shortcut 是 Android 7.1 (API Level 25) 的新特性,类似于苹果的 3D Touch ,但并不是压力感应,只是一种长按菜单.Shortcut 是受启动器限制的,也就是说国内大厂的定制系统大多数是不支持的,那些所谓的可以 pin 在桌面上的应用功能的快捷启动图标本质上就是 Shortcut . 二.Shortcut 在 Xamarin.Forms 中的实现分析 本文讨论的是动态 Shortcut 实现. 实现方式无非两种思路,一种 Nat

Xamarin.Forms学习之Page Navigation(一)

在最初接触Xamarin.Forms的时候,我是跟着Xamarin官方的名为“learning-xamarin-ebook”的pdf文档进行学习的,我在成功运行Hello world程序之后,我开始跟着pdf写上面的monkey实例,然而我却遇到了一个问题,我在列表页点击某一个Item的时候,不能如示例上面所展示的那样跳转到详细页面.也正因为此我在官方文档和电子书中寻找答案,也将自己的学习的东西做个简单的笔记和分享. 在Froms的中的提供了如下方法用于导航: Task PushAsync(Pa

Xamarin.Forms 调用 腾讯地图SDK

Xamarin.Forms研究了好一段时间了,最近一直在学习中,想尝试一下调用其他的SDK,就如腾讯地图SDK(申请容易). 完成此次项目得感谢以下链接: http://www.cnblogs.com/jtang/p/4698496.html 其他文档参考: 腾讯地图SDK(安卓)文档 这里面有详细的使用过程(当然里面的代码是不适用C#的,不过要从这里下载SDK,也有如何申请Key的过程,请参考阅读) Xamarin.Forms自定义每个平台的控件文档 里面有如何根据不同的平台条件下,调用其他页

Xamarin.Forms.Platform.Perspex, Xamarin Forms 的 Perspex(号称下一代WPF) 实现

Perspex, 跨平台的UI框架,加上Xamarin Forms的跨平台的中间层,这样同一套代码就可跨几乎所有已知平台,这其中包括旧版Windows, Linux及Mac OS. 目前,基本控件可显示,提供了一些简单的属性设置,效果见下图: 代码: https://github.com/zhongzf/Xamarin.Forms.Platform.Perspex

【转】Xamarin Forms 介绍

特此声明,本篇博文转自:http://blog.csdn.net/kinfey/article/details/29621381 什么是 Xamarin Forms ? Xamarin Forms 是一个高效创建跨平台用户界面的库 .通过Xamarin Forms 可以一次编码生成基于主流移动平台(iOS, Android, Windows Phone)的应用界面.和HTML 5 不同, 它是一套原生的界面解决方案,这意味着通过Xamarin Forms 渲染的界面是与底层API 紧密相连, 那