2016-03-30 1 views
0

У меня очень странная проблема. Когда я нажимаю на SearchView, сразу после того, как мой LinearLayout перемещает несколько пикселей вниз, около 10 или 20. Чтобы проиллюстрировать случай, я покажу вам несколько скриншотов.Нажмите на searchView перемещает мой LinearLayout вниз

Перед нажатием на SearchView:

enter image description here

После нажатия на SearchView:

enter image description here

Это метод OnCreateOptionsMenu:

@Override 
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
     Log.d(LOG_TAG,"OnCreateOptionsMenu-FragmentRegion"); 

     inflater.inflate(R.menu.menu_search,menu); 
     final MenuItem menuItem=menu.findItem(R.id.action_search); 
     SearchManager manager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); 
     final SearchView searchView= (SearchView) MenuItemCompat.getActionView(menuItem); 


     //hint color 
     SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); 
     searchAutoComplete.setHint("Stock/Index"); 

     if(Build.VERSION.SDK_INT>=16) { 
      View searchplate = (View) searchView.findViewById(android.support.v7.appcompat.R.id.search_plate); 
      final Drawable searchLine = ContextCompat.getDrawable(getActivity(), R.drawable.abc_textfield_search_material); 
      searchLine.setColorFilter(ContextCompat.getColor(getActivity(), R.color.colorAccent), PorterDuff.Mode.SRC_ATOP); 
      searchplate.setBackground(searchLine); // this method requires api level 16 
     } 
     searchView.setSearchableInfo(manager.getSearchableInfo(getActivity().getComponentName())); 
     mSuggestionsAdapter =new SuggestionsAdapter(getActivity(),null,SUGGESTIONS_LOADER); 
     searchView.setSuggestionsAdapter(mSuggestionsAdapter); 
     //on first launch will be always null, after rotating not 
     if(mSearchFilter!=null) { 
      MenuItemCompat.expandActionView(menuItem); 
      searchView.setQuery(mSearchFilter, true); 
     } 

     searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { 
      @Override 
      public boolean onQueryTextSubmit(String query) { 


       return false; 
      } 

      @Override 
      public boolean onQueryTextChange(String newText) { 
       ViewGroup.MarginLayoutParams params = 
         (ViewGroup.MarginLayoutParams)lLRegion.getLayoutParams(); 
       //LinearLayout.LayoutParams params= (LinearLayout.LayoutParams) 
       params.topMargin=-10; 
       lLRegion.setLayoutParams(params); 
       lLRegion.requestLayout(); 


       Log.d(LOG_TAG,"OnQueryTextChange"); 
       mSearchFilter= TextUtils.isEmpty(newText) ? null: newText; 
       getLoaderManager().restartLoader(SUGGESTIONS_LOADER,null,FragmentRegion.this); 
       return true; 
      } 
     }); 

     searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { 
      @Override 
      public boolean onSuggestionSelect(int position) { 
//    Cursor c= (Cursor) mSuggestionsAdapter.getItem(position); 
//    c.close(); 
       return false; 
      } 

      @Override 
      public boolean onSuggestionClick(int position) { 
       Cursor c = (Cursor) mSuggestionsAdapter.getItem(position); 
       String symbol = c.getString(SuggestionsAdapter.COL_TICKER); 
       String companyName = c.getString(SuggestionsAdapter.COL_NAME); 
       String securityType = c.getString(SuggestionsAdapter.COL_SECURITY_TYPE); 
       ((Callback)getActivity()).onItemSelected(symbol,companyName,securityType.toUpperCase()); 

       //clear focus for when returning from the previous activity 
       searchView.clearFocus(); 
       MenuItemCompat.collapseActionView(menuItem); 
       return true; 
      } 
     }); 

     super.onCreateOptionsMenu(menu, inflater); 
    } 

Как вы можете видеть Я попытался вставить программно верхний маркер внутри метода onQueryTextChange, но без успеха.

Это XML-

ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/scrollView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:id="@+id/llRegion" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <com.linearlistview.LinearListView 
      android:id="@+id/indexesList" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" /> 

     <com.linearlistview.LinearListView 
      android:id="@+id/newsList" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical" /> 
    </LinearLayout> 
</ScrollView> 

Заранее спасибо!

ответ

0

Добавление этой строки в манифесте решить мою проблему:

android:windowSoftInputMode="adjustPan" 

внутри тега активности

<activity 
      android:name=".MainActivity" 
      android:windowSoftInputMode="adjustPan" 
      android:launchMode="singleTop" 
      android:theme="@style/AppTheme1">