搜索查看错误的定位 [英] SearchView wrong alignment

查看:128
本文介绍了搜索查看错误的定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与搜索查看对齐的问题时,它的扩展。出于某种原因,当倒了对齐的权利,但扩大时左对齐。我所做的一切如下因素的ActionBarSherlock例子。

I'm having a problem with the alignment of the SearchView when it's expanded. For some reason, when collapsed it aligns rights, but when expanded it aligns left. I did everything folowing the ActionBarSherlock examples.

下面是问题的两张截图:

Here are two screenshots of the problem:

我还没有决定,如果我想使用动作条的标签。我不想展开时的搜索查看隐藏它们。但是,这是另一个问题。我的主要问题在这里是搜索查看的对齐exapanded时。我希望它保持正确对齐不管是什么。

I have yet to decide if I want to use ActionBar tabs. I don't want the searchView to hide them when expanded. But that's for another question. My main issue here is the alignment of the SearchView when exapanded. I want it to keep the right alignment no matter what.

下面是我的onCreateOptionsMenu:

Here's my onCreateOptionsMenu:

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getSupportMenuInflater().inflate(R.menu.menu_main, menu);
    searchMenuItem = menu.findItem(R.id.action_search);
    refreshMenuItem = menu.findItem(R.id.action_refresh);

    refreshMenuItem.setActionView(R.layout.refresh_progressbar);

    searchMenuItem.setOnActionExpandListener(new OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            flightsListAdapter.getFilter().filter("");
            return true;
        }
    }); 

    searchView = (SearchView)searchMenuItem.getActionView();
    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            flightsListAdapter.getFilter().filter(query);
            return true;
        }
    });
    searchView.clearFocus();

    return true;
}

和这里是我的menu_main.xml

And here is my menu_main.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
    android:id="@+id/action_search"
    android:title="@string/search"
    android:icon="@drawable/ic_search"
    android:showAsAction="always|collapseActionView"
    android:actionViewClass="com.actionbarsherlock.widget.SearchView" />

<item
    android:title="@string/date"
    android:icon="@drawable/ic_compose"
    android:showAsAction="always" >
    <menu>
        <item
            android:id="@+id/menuYesterday"
            android:title="Yesterday"/>
        <item
            android:id="@+id/menuToday"
            android:title="Today"/>
        <item
            android:id="@+id/menuTomorrow"
            android:title="Tomorrow"/>
    </menu>
</item>

<item
    android:id="@+id/action_refresh"
    android:icon="@drawable/ic_refresh"
    android:showAsAction="always"
    android:title="@string/action_refresh" />
</menu>

感谢您的阅读:)

推荐答案

确定。只是为了共同的知识,我回答我自己的问题。

Ok. Just for the sake of common knowledge, I'm answering my own question.

诀窍是删除collapseActionView的SerchView。有一次,我删除了,该搜索查看exanded时住宿的地方(右侧)。

The trick was to remove "collapseActionView" on the SerchView. Once I removed that, the SearchView stays in place (to the right) when exanded.

这篇关于搜索查看错误的定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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