Android Gallery 在两个视图之间启动

发布于 2024-11-18 10:20:05 字数 496 浏览 4 评论 0原文

我有一个带有画廊的 Android 应用程序,可以在文本切换器视图之间切换。它总是在两个文本切换器视图之间开始。为什么会出现这种情况?我将选择设置为特定位置。

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); g = (画廊) findViewById(R.id.画廊); g.setAnimationDuration(200); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    g.setAdapter(hello);
    g.setSpacing(20);
    g.setSelection(2);

I have an android application with a gallery that switches between textswitcher views. It always starts in between two textswitcher views. Why does this happen? I'm setting the selection to a specific position.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
g = (Gallery) findViewById(R.id.gallery);
g.setAnimationDuration(200);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    g.setAdapter(hello);
    g.setSpacing(20);
    g.setSelection(2);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一笔一画续写前缘 2024-11-25 10:20:05

虽然这是一个老问题,但我也遇到了同样的问题,也许它对其他人有帮助。这是我的适配器的关键部分:

    public View getView(int position, View convertView, ViewGroup parent) {

        Display display = ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int width = display.getWidth();

        LayoutInflater inflater = LayoutInflater.from(c);
        View view = inflater.inflate(R.layout.date_list_item, parent,false);
        view.setLayoutParams(new Gallery.LayoutParams(width/3, Gallery.LayoutParams.MATCH_PARENT));

我想同时显示三个项目,所以我采用了 parent.getWidth()/3。然而,这导致画廊在两种观点之间开始。获取上面代码示例中显示的显示宽度对我来说效果很好

Although this is an old question, I had the same problem and maybe it helps others. This was the crucial part of my Adapter:

    public View getView(int position, View convertView, ViewGroup parent) {

        Display display = ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int width = display.getWidth();

        LayoutInflater inflater = LayoutInflater.from(c);
        View view = inflater.inflate(R.layout.date_list_item, parent,false);
        view.setLayoutParams(new Gallery.LayoutParams(width/3, Gallery.LayoutParams.MATCH_PARENT));

I wanted to have three items shown at the same time, so I took parent.getWidth()/3. however this led the gallery to start between two views. Getting the displays width shown in the upper code-sample worked fine for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文