我正在使用Xamarin.Forms
并定位iOS
和Android
。
XAML
<?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="XilnexOTM.Views.LoginPage"
BackgroundImage="bg1.png" >
<ScrollView>
<StackLayout Orientation="Vertical">
<Label Text="PICTURE" />
<Label Text="PIC 2" />
<Entry Placeholder="Username" />
<Entry Placeholder="Password" IsPassword="true"/>
<Button x:Name="btn_Login"
Text="Login"
BackgroundColor="#FF0000"/>
</StackLayout>
</ScrollView>
</ContentPage>
将CSS
中的概念应用于Xamarin.Forms
吗?
xx {
background-size: cover;
background-position: right bottom;
}
答案 0 :(得分:20)
使用ContentPage.BackgroundImage
,您无法控制宽高比。而是使用Image
与AbsoluteLayout
相结合(以及设置Aspect
的{{1}}属性):
Image
答案 1 :(得分:2)
在MainActivity中,您可以使用AdjustPan或AdjustResize:
class ViewController: UIViewController, UITableViewDelegate {
var NumberOfPersons = 0
var NameOfPerson = [String]()
override func viewDidLoad() {
super.viewDidLoad()
parseJSON()
}
func parseJSON(){
do {
let data = NSData(contentsOfURL: NSURL(string: "http://zzzzzz.com/API/name.php")!)
let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers)
let NumberOfPersons = jsonResult.count
**LOOP THROUGH THE JSON ARRAY**
} catch let error as NSError {
print(error)
}
}
}
答案 2 :(得分:1)
我更喜欢按代码进行操作,这是我的解决方案:
我的App.xaml中总是有这样的设备屏幕:
public static double ScreenWidth { get; set; }
public static double ScreenHeight { get; set; }
然后在我的Android主要活动中:
Passapp.App.ScreenWidth = (double)(Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density);
Passapp.App.ScreenHeight = (double)(Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density);
在我的iOS AppDelegate中:
App.ScreenWidth = UIScreen.MainScreen.Bounds.Width;
App.ScreenHeight = UIScreen.MainScreen.Bounds.Height;
因此,当您拥有屏幕宽度和高度时,您可以在任何页面中执行此操作:
public partial class MyPage : ContentPage
{
public MyPage()
{
InitializeComponent();
NavigationPage.SetHasNavigationBar(this, false);
var layout = new AbsoluteLayout();
#if __ANDROID__
BackgroundImage = "Background";
#endif
#if __IOS__
Image img = new Image()
{
Source = "Background",
Aspect = Aspect.Fill
};
layout.Children.Add(img, new Rectangle(0, 0, App.ScreenWidth, App.ScreenHeight));
#endif
Content = layout;
}
}