不确定的水平进度低于动作条使用AppCompat? [英] Indeterminate Horizontal ProgressBar BELOW ActionBar using AppCompat?

查看:128
本文介绍了不确定的水平进度低于动作条使用AppCompat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找如何把下面使用AppCompat操作栏上的不确定水平进度条的答案。我能得到水平进度条出​​现,但它在操作栏的顶部。我想这下/下面的操作栏有点像Gmail的如何做它(只是没有拉刷新)。

I have been looking for answers on how to place the indeterminate horizontal progress bar below the action bar using AppCompat. I'm able to get the horizontal progress bar to appear, but it is at the top of the action bar. I want it under/below the action bar kind of like how gmail does it (except without the pull to refresh).

我用下面的code有进度条显示:

I used the following code to have the progress bar appear:

supportRequestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main_activity);
setSupportProgressBarIndeterminate(Boolean.TRUE);
setSupportProgressBarVisibility(true);

但这个地方在操作栏上方的水平进度条。任何人都知道如何把下面的操作栏上的进度条?

but this places the horizontal progress bar at the top of the action bar. Anyone know how to place the progress bar below the action bar?

推荐答案

我遇到类似的问题,最近,并通过创建自己的进度,然后通过控制内容视图的共达()对准它解决了这个问题。

I faced a similar problem recently and solved it by creating my own progressbar and then aligning it by manipulating getTop() of the content view.

所以首先创建进度。

final LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 20); //Use dp resources


mLoadingProgressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
mLoadingProgressBar.setIndeterminate(true);
mLoadingProgressBar.setLayoutParams(lp);

将它添加到窗口(装饰视图)

final ViewGroup decor = (ViewGroup) getWindow().getDecorView();
decor.addView(mLoadingProgressBar);

另外,为了用得到它的正确位置我是个 ViewTreeObserver 监听,直到认为已经奠定了(又名View.getTop()心不是0)。

And in order to get it to its correct position Im using a ViewTreeObserver that listens until the view has been laid out (aka the View.getTop() isnt 0).

final ViewTreeObserver vto = decor.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        final View content = getView(android.R.id.content);

        @Override
        public void onGlobalLayout() {
            int top = content.getTop();

            //Dont do anything until getTop has a value above 0.
            if (top == 0)
                return;

            //I use ActionBar Overlay in some Activities, 
            //in those cases it's size has to be accounted for
            //Otherwise the progressbar will show up at the top of it
            //rather than under. 

            if (getSherlock().hasFeature((int) Window.FEATURE_ACTION_BAR_OVERLAY)) {
                top += getSupportActionBar().getHeight();
            }

            //Remove the listener, we dont need it anymore.
            Utils.removeOnGlobalLayoutListener(decor, this);

            //View.setY() if you're using API 11+, 
            //I use NineOldAndroids to support older 
            ViewHelper.setY(mLoadingProgressBar, top);
        }
    });

希望是有道理的为您服务。祝你好运!

这篇关于不确定的水平进度低于动作条使用AppCompat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆