我正在尝试构建一个以纵向和横向模式显示书籍的应用程序.很明显,有1页以肖像方式显示,2页以横向方式显示.每个模式都工作得很好但是当我将方向从纵向更改为横向时,viewPager尝试从纵向模式获取2个页面,而不是尝试从横向模式获取2个双页...实际上FragmentStatePagerAdapter保留了2个片段以纵向创建并在为横向模式创建2个双页之前使用它们.如果我再次以纵向模式切换,FragmentStatePagerAdapter使用以前在横向模式下创建的2个片段,所以我再次看到1个双页而不是1个单页等.如果我继续切换方向,我得到一个OutOfMemoryError,因为FragmentStatePagerAdapter永远不会在方向改变时冲洗它的碎片.
这里有2个用例,以便于理解:
我向右滑动,我看到第5页和第6页确定
我以纵向模式启动viewPager
我向左滑动,我看到第2页和第3页确定
public class PlayerFragmentActivity extends FragmentActivity {
private Intent mIntent;
private ViewPager mPortraitPager;
private ViewPager mLandscapePager;
private Boolean mIsLandscape;
private String mKey;
private int mNbPages;
private int mNbDoublePages;
private PageFactory mPageFactory;
private DoublePageFactory mDoublePageFactory;
private PagerAdapter mPagerAdapter;
@Override
protected void onStop(){
super.onStop();
mPagerAdapter = null;
mDoublePageFactory = null;
mPageFactory = null;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); …
Run Code Online (Sandbox Code Playgroud)android fragment screen-orientation android-fragments android-viewpager
我尝试开发第一个从网上下载图像并在gridview中显示它们的应用程序.gridview是主Activity的片段.下载过程是使用onCreate函数中的AsyncTask完成的.为了在更改方向时不再下载图像,我android:configChanges="orientation|screenSize"
在Android Manifest中设置了它.然后onCreate函数只调用一次,一切都很好......除了我必须在横向模式下对gridview片段的布局进行一些更改.所以我创建了2个布局表:fragment_library.xml
并fragment_library_land.xml
在布局/文件夹中.为了使这些更改起作用,我尝试使用onConfigurationChanged函数手动更改库片段的布局.在运行时,程序会评估函数并传递好的情况(纵向或横向),但使用的布局仍然是纵向模式:fragment_library.xml
...
public class LibraryFragment extends Fragment {
public GridView gridview;
private Boolean isImageAdapterPopulated = false;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
GetLibraryTask getLibraryTask = new GetLibraryTask(this);
getLibraryTask.execute(Config.URL + "action=getLibrary");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null)
return null;
// gridview
View V = inflater.inflate(R.layout.fragment_library, container, false);
gridview = (GridView)V.findViewById(R.id.gridview);
if(this.isImageAdapterPopulated)
this.setGridAdapter();
return V;
}
@Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == …
Run Code Online (Sandbox Code Playgroud) 我正在尝试gccgo
使用 Golang安装以测试 Protocol Buffers 3……我必须承认,我在 8 年后(而且我不是母语人士)回到了开发领域,所以,感谢您的放纵。谢谢 :)
所以,经过几次阅读,我决定从这个 repo 的 README 开始:https : //github.com/golang/protobuf
协议缓冲区的最后一个版本安装在我的 Mac 上(据protobuf-cpp-3.11.4.tar.gz
我所知)https://github.com/protocolbuffers/protobuf/releases/tag/v3.11.4
$ ls $GOBIN
dlv* gocode* godef* gopkgs* protoc-gen-go*
go-outline* gocode-gomod* golint* goreturns*
Run Code Online (Sandbox Code Playgroud)
当然,从https://golang.org/安装 Go 编译器和工具,请参阅 https://golang.org/doc/install了解详细信息,或者,如果您使用的是 gccgo,请按照https://golang 上的说明进行操作。组织/文档/安装/gccgo
我的理解是我需要安装gccgo
哪个是gcc编译器的一个分支。然后我读到这gccgo
实际上只是使用--enable-languages=c,c++,go
选项配置的 gcc 编译器的自定义构建( src https://golang.org/doc/install/gccgo)......那么为什么 repos 上有一个特殊的分支它在哪里?( https://gcc.gnu.org/git.html ) 我
我只是放弃尝试从git存储库下载gccgo分支并找到一个svn repo:
$ svn checkout svn://gcc.gnu.org/svn/gcc/branches/gccgo gccgo`
gccgo$ ./configure --enable-languages=c,c++,go
... …
Run Code Online (Sandbox Code Playgroud) 我有一个my-project
多根工作区:
- my-project\n - my-project-api-gateway\n - another-root-folder-we-dont-care-about\n
Run Code Online (Sandbox Code Playgroud)\n这是我的launch.json
配置文件my-project-api-gateway
- my-project\n - my-project-api-gateway\n - another-root-folder-we-dont-care-about\n
Run Code Online (Sandbox Code Playgroud)\n调试控制台输出
\nStarting: /Users/me/go/bin/dlv dap --check-go-version=false --listen=127.0.0.1:53890 --log-dest=3 from /Users/me/path/to/project/src\nDAP server listening at: 127.0.0.1:53890\nType \'dlv help\' for list of commands.\n2022/07/20 10:30:52 Error loading .env file\nProcess 13526 has exited with status 1\nDetaching\ndlv dap (13508) exited with code: 0\n
Run Code Online (Sandbox Code Playgroud)\n感谢您的帮助
\n\xe2\x9d\xaf dlv version\nDelve Debugger\nVersion: 1.8.2\n\n\xe2\x9d\xaf go version\ngo version go1.18 darwin/amd64\n\n\xe2\x9d\xaf gopls …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将 svelte SPA 迁移到 Sveltekit 中。
在我的 SPA 中,通信模式就是我所说的“控制器组件”,它负责显示一些组件、监听它们的事件并相应地更新应用程序。总的来说,它看起来像这样的 REPL:
https://svelte.dev/repl/47bd3f8004624a3c95653b1f1aefd8ee?version=3.46.4
正如您在此示例中所看到的,该序列相当简单: 应用程序状态 1) 应用程序显示 CompA 和 CommonComp 应用程序状态 2) CompA 在安装后立即触发 doSomething 函数 应用程序状态 3) 应用程序然后调用 commonComp.setTitle 并在中显示 CompB CompA所在地
在 SvelteKit 中,我很难做类似的事情,因为我不明白如何将数据从带槽的子组件传递到包含槽的组件,反之亦然。无论如何,这导致我进行了这次尝试:
我需要2条路线:
因为 CommonComp 在每个状态下始终可见,所以我认为它应该驻留在 __layout.svelte 文件中。
...这让我看到了下面的草稿,其中的评论解释了我遇到的访问问题。
/src/routes/__layout.svelte
<slot />
<CommonComp />
Run Code Online (Sandbox Code Playgroud)
/src/routes/PageA.svelte
<script>
import { goto } from "$app/navigation";
import CompA from "$lib/CompA.svelte";
function handleDoSomethingFinished() {
goto("/test/pageB");
}
</script>
<CompA on:do_something_finished={handleDoSomethingFinished} />
Run Code Online (Sandbox Code Playgroud)
/src/lib/CompA.svelte …
我对尝试在浏览器代码中使用 geofire-common 感到有点困惑。
一开始,我对 NodeJS 进行了成功的尝试,它使用了Google 文档中geofire-common
引用的内容,其代码如下所示:
import { createRequire } from 'module'; // <------ trick to get a require function
const require = createRequire(import.meta.url);
const { initializeApp, cert } = require('firebase-admin/app');
const { getFirestore } = require('firebase-admin/firestore');
const serviceAccount = require('./serviceAccountKey.json');
initializeApp({
credential: cert(serviceAccount),
});
const db = getFirestore();
const geofire = require('geofire-common'); //<---------- geofire-common
Run Code Online (Sandbox Code Playgroud)
然后,我想从浏览器端完成这项工作......我偶然发现了这个例子。在这个例子中,我可以看到一个“require”函数,所以我猜它与老式的 commonJS 模块有关:
const geofire = require('geofire-common');
Run Code Online (Sandbox Code Playgroud)
Require
不是标准 JavaScript API 的一部分,应该是 NodeJS 特定的(这有点奇怪,因为我认为这个例子是浏览器代码),所以我尝试使用 ES6 导入。
import {geofire} from …
Run Code Online (Sandbox Code Playgroud) 我对 svelte 尤其是 SvelteKit 还很陌生。目前,我正在做 2 个项目。
第一个是 SPA,其中我使用svelte-spa-router来管理不同的状态,并提供像在老式网站中那样来回导航的功能。这非常有效:)
第二个项目是 SvelteKit 应用程序。我有 3 个用例:
首先,我认为如果每个用例需要的话能够预取某种 JSON 数据会很有趣,但另一方面,我不想为每个子用例创建一个路由页面因为我不希望用户每次执行简单操作时都刷新页面。因此,我使用 3 条路线在这 3 个“用例”之间导航:
src/routes/search_product/+page.svelte
src/routes/create_product_page/+page.svelte
src/routes/show_top_10_products/+page.svelte
Run Code Online (Sandbox Code Playgroud)
现在,我遇到了一个问题...创建产品页面需要 3 个步骤。这 3 个步骤由以下 3 个不同的 Svelte 组件表示:
EnterProductBasicInfo.svelte
UploadPictures.svelte
GivePrices.svelte
如果用户正在创建产品页面并处于步骤 2),则会向他显示该UploadPictures.svelte
组件....但是如果他按后退按钮,他将退出该create_product_page
路线,而不是返回到步骤 1)是EnterProductBasicInfo.svelte
组件。
所以,我想我可以使用我svelte-spa-router
在 SPA 中使用过的,但我在这里询问专家 SvelteKit 中是否有另一个内置解决方案能够管理路线,而无需每次刷新整个页面路线改变。如果您有一些关于 SPA、SSR、预加载与预取的好链接,我会接受它,因为它对我来说仍然有点模糊。
非常感谢你的帮助。