首先,如果我不遵守任何 SO 规则,我想道歉,因为这是我的第一个问题。
我想要完成的是在我的页面中有一个方形的gridLayout。该行为应该等同于拥有一个带有stretch="aspectFit"的元素。
如果建议的解决方案可以让我强制执行任何给定的纵横比,而不仅仅是一个正方形,那将是一个不错的加分,因为它可以让我在未来解决多种情况。或者如果它可以应用于任何 Layout 元素,那也很好。
该解决方案可以随心所欲,并且 GridLayout 可以以您需要的任何方式嵌套以完成此任务。
我已经尝试过像这样破解它:
<GridLayout rows="*,auto,*" columns="*,auto,*" backgroundColor="green">
<Image row="1" col="1" src="~/Images/1px-black.png" stretch="aspectFit" width="100%"></Image>
<StackLayout row="1" col="1" orientation="vertical" backgroundColor="lightgray">
<Label text="Label 1" width="100%" height="25%" backgroundColor="red"></Label>
<Label text="Label 2" width="100%" height="25%" backgroundColor="green"></Label>
<Label text="Label 3" width="100%" height="25%" backgroundColor="blue"></Label>
<Label text="Label 4" width="100%" height="25%" backgroundColor="yellow"></Label>
</StackLayout>
</GridLayout>
Run Code Online (Sandbox Code Playgroud)
视觉上它似乎有效,但 GridLayout 的内容没有适当地填充它
PS:我刚刚注意到在我选择的示例中,我试图制作方形的布局元素是嵌套的 StackLayout,但它的想法是相同的。我需要一种方法来使嵌套布局元素平方。
我正在尝试开发一个 nativescript 插件来使用 Azure SDK 执行一些功能。SDK的文档如下所示:
所以我在我的插件中添加了以下功能:
MobileServiceUser.newUser = function (userId, client) {
var userObject = com.microsoft.windowsazure.mobileservices.authentication.MobileServiceUser(userId); // causing the error
client.setCurrentUser(userObject);
};
Run Code Online (Sandbox Code Playgroud)
UserId 是一个字符串。
但是,最上面一行抛出错误:
JS:错误:试图将无效的“this”链接到 Java 对象
我有一个完整的 repo,显示了在Github上创建这个问题的最小实现。
对于如何解决此问题的任何建议,我将不胜感激。
我想从电子邮件中的链接打开我的 android 应用程序。通过 Stackoverflow 搜索,看起来可以使用指向我控制的 url 的 '' 来实现。尽管在使用 Nativescript 构建的 android 应用程序的情况下,我有点困惑如何使用它。只是添加一个我拥有的具有特定数据路径的 url 是唯一需要做的事情吗?在这种情况下,会出现一个应用程序选择器对话框。以这种方式打开应用程序时可以触发某个事件吗?谢谢您的帮助。下面是我需要做的事情的示例。
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
<!-- Custom Path data -->
<data
android:host="www.some.company.com"
android:path="/something"
android:scheme="http"/>
</intent-filter>
Run Code Online (Sandbox Code Playgroud) 嗨,我的模板如下所示
<ListView [items]="modules">
<template let-item="item" >
<StackLayout orientation="vertical">
<Switch (checkedChange)="onSwitchModule(item.id,$event)" [checked]="item.active"></Switch>
</StackLayout>
</template>
</ListView>
Run Code Online (Sandbox Code Playgroud)
我的控制器是
ngOnInit() {
this._moduleService.getUserModules()
.subscribe(
response=>{
this.modules = response.data;
}
)
}
onSwitchModule(itemId) {
console.log(itemID); //Gets called on initial true binding on switch checked
}
Run Code Online (Sandbox Code Playgroud)
每次页面加载时 onSwitchModule 都会被调用,item.active 在任何项目上为 true,如何处理?
注意:Nativescript 初学者
我正在使用Nativescript/Angular 2构建应用程序
我希望能够从 URL 下载文件并将其保存到设备中普通用户可以轻松找到它的位置。我相信,下载将是这两个最好的地方iOS和Android。如果我错了,请纠正我。
该文件可以是任何文件类型,而不仅仅是图像。所以主要是spreadsheet,word document,pdf,png,jpg,等。
我在网上和文档中搜索过。该文档描述了一种名为getFile的方法,该方法获取文件并将其保存到您的设备。
我在我的代码中实现了这一点,如下所示:
download (id) {
console.log('Download Started');
getFile("https://raw.githubusercontent.com/NativeScript/NativeScript/master/apps/tests/logo.png").then(function (r) {
console.log(r.path);
}, function (e) {
//// Argument (e) is Error!
});
}
Run Code Online (Sandbox Code Playgroud)
这样做的问题是它将它保存到非用户可访问的位置,例如:
/data/user/0/com.myapp.example/files/logo.png
Run Code Online (Sandbox Code Playgroud)
更新:
我也试过直接指定路径:
fs.knownFolders.documents();
Run Code Online (Sandbox Code Playgroud)
但是,此方法获取用户或外部应用程序无法访问的当前应用程序的文档文件夹
我有以下标记:
<StackLayout paddingLeft="15" paddingRight="15" dock="top" >
<Label textWrap="true">
<Label.formattedText>
<FormattedString>
<FormattedString.spans>
<Span text="By checking 'yes' I understand that this is a legally valid and binding written agreement, and I indicate that I have read, understand, and agree to the terms of my " />
<Span text="Agreement. " foregroundColor="#3aba90" tap="viewAgreemnent" />
<Span text="Also, by checking 'yes', I certify that I have read and agree to accept electronically the " />
<Span text="Privacy Policy." foregroundColor="#3aba90" tap="viewPolicy" />
</FormattedString.spans>
</FormattedString>
</Label.formattedText>
</Label>
</StackLayout> …Run Code Online (Sandbox Code Playgroud)我有一个 OpenEdge 数据库,我创建了一个 REST 服务,并且能够从外部世界对它进行 CRUD。我创建了一个可以从 REST 服务等中提取数据的 Nativescript 应用程序,但现在我想要推送通知。
我知道 Progress Kinvey 后端和具有推送通知功能的 Firebase 后端,但我不想使用它们。
有没有办法在我的 REST 服务器等上创建我自己的推送通知?
rest openedge push-notification nativescript angular2-nativescript
我将 Angular 与 Nativescript Schematics 一起使用。我已经安装了 nativescript-ui-sidedrawer。当我跑
tns run ios --bundle
Run Code Online (Sandbox Code Playgroud)
本机版本已编译并部署到设备,但是当我运行时
ng serve
Run Code Online (Sandbox Code Playgroud)
网络版本失败,出现几个错误,都非常相似。第一个是
ERROR in ./node_modules/tns-core-modules/ui/builder/component-builder/component-builder.js
Module not found: Error: Can't resolve '../../../platform' in '/Users/markdev/Documents/Code/mydrawer/node_modules/tns-core-modules/ui/builder/component-builder'
Run Code Online (Sandbox Code Playgroud)
所有的错误都与路径有关。
如果我浏览到上面给出的错误并编辑“component-builder.js”,并将路径更改为
~/node_modules/tns-core-modules/platform
Run Code Online (Sandbox Code Playgroud)
从
../../../platform
Run Code Online (Sandbox Code Playgroud)
然后在运行“ng serve”时,该特定错误不会显示在输出的错误列表中。
但是……当我跑的时候
tns run ios --bundle
Run Code Online (Sandbox Code Playgroud)
我得到
ERROR in ../node_modules/tns-core-modules/ui/builder/component-builder/component-builder.js
Module not found: Error: Can't resolve '/Users/markdev/Documents/Code/mydrawer/src/node_modules/tns-core-modules/platform' in '/Users/markdev/Documents/Code/mydrawer/node_modules/tns-core-modules/ui/builder/component-builder'
@ ../node_modules/tns-core-modules/ui/builder/component-builder/component-builder.js 7:15-66
@ ../node_modules/tns-core-modules/ui/builder/builder.js
@ ../node_modules/tns-core-modules/ui/repeater/repeater.js
@ ../node_modules/tns-core-modules/bundle-entry-points.js
@ ./main.ns.ts
Run Code Online (Sandbox Code Playgroud)
如果我在设备上打开应用程序,我会得到
*** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Error: Cannot find module …Run Code Online (Sandbox Code Playgroud) 我有一个现有的 Nativescript angular 应用程序,可以在我的 Android 模拟器上运行,没有任何问题。前几天,我使用以下命令将 tns-android 版本从 4.1.3 更新到 5.0.0:
tns platform update android
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用以下命令再次运行模拟器
tns run android --bundle
Run Code Online (Sandbox Code Playgroud)
但是,由于以下错误,自更新以来我一直无法使应用程序运行:
error: resource xml/network_security_config (aka org.nativescript.app:xml/network_security_config) not found.
Run Code Online (Sandbox Code Playgroud)
我的 AndroidManifest.xml 看起来像这样:
<application
android:name=...
android:debuggable="true"
android:networkSecurityConfig="@xml/network_security_config">
...
</application>
Run Code Online (Sandbox Code Playgroud)
我有一个位于 /App_Resouces/Android/xml 的 network_security_config.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<debug-overrides>
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
Run Code Online (Sandbox Code Playgroud)
我尝试删除平台并再次添加它,但发生了同样的错误。我还尝试删除平台并安装特定版本的 android 平台,但仍然没有运气。
当我检查我的 git 历史时,我可以看到 repo 中唯一被跟踪的文件是 package.json 文件。我尝试恢复到我知道有效的最后一次提交,但仍然看到相同的错误。
之前
"tns-android": {
"version": "4.1.3"
}
Run Code Online (Sandbox Code Playgroud)
更新后
"tns-android": {
"version": "5.0.0"
}
Run Code Online (Sandbox Code Playgroud)
让我的构建工作的唯一方法是从 …
今天我尝试重写 Snapchat 的 UI 作为一个挑战。我从登陆页面开始,但我在底部的按钮上遇到了一个问题,它们下面有一个间隙。
我很惊讶它不会自然地 100% 下降到底部,但是有没有办法做到这一点?我可以margin-top在底部堆栈布局上做,但有更好的方法吗?
更新:放在margin-top底部StackLayout只是将高度向上推,它不会让它下降,似乎定位被锁定在屏幕的 96% 左右。
这是我的游乐场代码 - https://play.nativescript.org/?template=play-tsc&id=zRSpSr
nativescript ×10
android ×3
angular ×3
typescript ×2
aspect-fit ×1
aspect-ratio ×1
azure ×1
css ×1
grid-layout ×1
http ×1
javascript ×1
openedge ×1
rest ×1