两种方式实现类似qq搜索的切换

2023-05-16

转载自:点击打开链接

http://www.csdn.net/tag/searchview

qq的搜索功能在点击搜索框时整个页面上移,出现透明布局。该效果是模仿iOS实现的,但是在Android也是很容易实现的。于是就花了点时间仿照效果写了一个demo。可能实现方式并不是完全相同。

具体请看效果图:


详细说明略。第一种是利用隐藏的透明LinearLayout实现效果。第二、三种是通过PopupWindow实现的,只有一处区别,即搜索框的两种状态。第二种采用的是ListView的addHeaderView实现的。

不多说直接上代码

第一种

    /**********************************************************  
     * @文件名称:MainActivity.java  
     * @创建时间:2014年11月21日 下午8:12:24 
     * @修改历史:2014年11月21日 
     **********************************************************/  
    package com.jinlin.searchview;  
      
    import java.util.ArrayList;  
    import java.util.List;  
      
    import android.app.Activity;  
    import android.content.Context;  
    import android.os.Bundle;  
    import android.util.Log;  
    import android.view.KeyEvent;  
    import android.view.MotionEvent;  
    import android.view.View;  
    import android.view.View.OnClickListener;  
    import android.view.View.OnTouchListener;  
    import android.view.animation.Animation;  
    import android.view.animation.Animation.AnimationListener;  
    import android.view.animation.TranslateAnimation;  
    import android.view.inputmethod.EditorInfo;  
    import android.view.inputmethod.InputMethodManager;  
    import android.widget.ArrayAdapter;  
    import android.widget.Button;  
    import android.widget.EditText;  
    import android.widget.LinearLayout;  
    import android.widget.ListView;  
    import android.widget.TextView;  
    import android.widget.TextView.OnEditorActionListener;  
    import android.widget.Toast;  
      
    /** 
     * @author J!nl!n 
     * @date 2014年11月21日 
     * @time 下午8:12:24 
     * @type MainActivity.java 
     * @todo 
     */  
    public class Activity1 extends Activity implements OnClickListener{  
        protected static final String TAG = Activity1.class.getSimpleName();  
      
        // 容器布局  
        private LinearLayout container;  
      
        // 标题栏布局  
        private View titleView;  
      
        private View searchView;  
      
        private ListView listView;  
      
        // 输入框是否获取到焦点  
        private static boolean isFocused = false;  
      
        // 图标居中输入框  
        private EditText et_search;  
      
        // 真是输入框  
        private EditText et_input;  
      
        // 取消按钮  
        private Button btn_cancel;  
      
        // 显示或隐藏软键盘  
        private enum KeyBoardType {  
            show, hide;  
        }  
          
      
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.activity1);  
            initView();  
        }  
      
        private List<String> getData() {  
            List<String> data = new ArrayList<String>();  
            for (int i = 0; i < 100; i++) {  
                data.add("测试数据" + i);  
            }  
            return data;  
        }  
      
        /** 
         * 【未做验证】这里需要注意在removeView之后,标题栏设置的监听事件是否失去,倘若在点击取消调用addView方法之后是否需要重新设置监听 
         */  
        private void initView() {  
            // 找到整个容器的布局  
            container = ((LinearLayout) findViewById(R.id.container));  
            // 获取标题栏布局  
            titleView = findViewById(R.id.title_header);  
              
            listView = (ListView) findViewById(R.id.listview);  
            listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, getData()));  
              
            // 找到隐藏的搜索布局  
            searchView = findViewById(R.id.floatview);  
      
            et_search = (EditText) findViewById(R.id.et_search);  
            et_input = (EditText) findViewById(R.id.et_input);  
            // 取消按钮  
            btn_cancel = (Button) findViewById(R.id.btn_cancel);  
            // 取消按钮设置监听  
            btn_cancel.setOnClickListener(this);  
      
            et_search.setOnTouchListener(new OnTouchListener() {  
                @Override  
                public boolean onTouch(View v, MotionEvent event) {  
                    switch (event.getAction()) {  
                    case MotionEvent.ACTION_DOWN:  
                        isFocused = true;  
                        // 显示隐藏的布局  
                        showSearchView(titleView);  
                        // 对软键盘及焦点的操作  
                        doSomething();  
                        break;  
                    }  
                    return false;  
                }  
            });  
        }  
      
        private void doSomething() {  
            et_search.setFocusable(false);  
            if (isFocused) {  
                Toast.makeText(Activity1.this, "获取焦点", Toast.LENGTH_SHORT).show();  
                et_input.setFocusable(true);  
                et_input.setFocusableInTouchMode(true);  
                et_input.requestFocus();  
                // 显示软键盘  
                operateKeyboard(KeyBoardType.show, container);  
            }  
        }  
          
        /** 
         * 隐藏软键盘 
         *  
         * @param v 
         */  
        private void operateKeyboard(KeyBoardType type, View v) {  
            InputMethodManager imm = (InputMethodManager) v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);  
            if (type == KeyBoardType.show)  
                imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);  
            else  
                imm.hideSoftInputFromWindow(v.getWindowToken(), 0);  
            setKeyboardDoneListener();  
        }  
      
        private void setKeyboardDoneListener() {  
            // 软键盘回车完成监听  
            et_input.setOnEditorActionListener(new OnEditorActionListener() {  
                @Override  
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {  
                    if (actionId == EditorInfo.IME_ACTION_DONE) {  
                        operateKeyboard(KeyBoardType.hide, v);  
                        Log.d("1111", "done");  
      
                        // do something  
                        Toast.makeText(Activity1.this, et_input.getText().toString().trim(), Toast.LENGTH_SHORT).show();  
                        return true;  
                    }  
                    return false;  
                }  
            });  
        }  
      
        public void showSearchView(View view) {  
              
            Animation translateAnimation = new TranslateAnimation(0, 0, 0, -getHeight(view));  
            translateAnimation.setDuration(300);  
            container.startAnimation(translateAnimation);  
            translateAnimation.setAnimationListener(new AnimationListener() {  
      
                @Override  
                public void onAnimationStart(Animation arg0) {  
                }  
      
                @Override  
                public void onAnimationRepeat(Animation arg0) {  
                }  
      
                @Override  
                public void onAnimationEnd(Animation arg0) {  
                    TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0);  
                    container.setAnimation(anim);  
                      
                    titleView.setVisibility(View.GONE);  
                    titleView.setPadding(0, -getHeight(titleView), 0, 0);  
                    // 显示隐藏的布局  
                    searchView.setVisibility(View.VISIBLE);  
                }  
            });  
        }  
          
        /** 
         *  
         */  
        private int getHeight(View view) {  
            return view.getHeight();  
        }  
      
        @Override  
        public void onWindowFocusChanged(boolean hasFocus) {  
            super.onWindowFocusChanged(hasFocus);  
            Toast.makeText(this, "高度是:" + getHeight(titleView), Toast.LENGTH_SHORT).show();  
        }  
          
        private void resetUI(View view) {  
            operateKeyboard(KeyBoardType.hide, view);  
            // 继续隐藏搜索布局  
            searchView.setVisibility(View.GONE);  
              
            titleView.setPadding(0, 0, 0, 0);  
            titleView.setVisibility(View.VISIBLE);  
              
            Animation translateAnimation = new TranslateAnimation(0, 0, -getHeight(titleView), 0);  
            translateAnimation.setDuration(300);  
            container.startAnimation(translateAnimation);  
            translateAnimation.setAnimationListener(new AnimationListener() {  
      
                @Override  
                public void onAnimationStart(Animation arg0) {  
                      
                }  
      
                @Override  
                public void onAnimationRepeat(Animation arg0) {  
      
                }  
      
                @Override  
                public void onAnimationEnd(Animation arg0) {  
                    TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0);  
                    container.setAnimation(anim);  
                }  
            });  
        }  
      
        @Override  
        public void onClick(View v) {  
            switch (v.getId()) {  
            case R.id.btn_cancel:  
                isFocused = false;  
                resetUI(v);  
                break;  
      
            default:  
                break;  
            }  
        }  
      
    }  

第二种

    /**********************************************************  
     * @文件名称:Activity2.java  
     * @创建时间:2014年11月22日 下午9:54:31 
     * @修改历史:2014年11月22日 
     **********************************************************/  
    package com.jinlin.searchview;  
      
    import java.util.ArrayList;  
    import java.util.List;  
    import java.util.Timer;  
    import java.util.TimerTask;  
      
    import android.app.Activity;  
    import android.content.Context;  
    import android.graphics.Rect;  
    import android.graphics.drawable.BitmapDrawable;  
    import android.os.Bundle;  
    import android.text.Editable;  
    import android.text.TextWatcher;  
    import android.view.Gravity;  
    import android.view.LayoutInflater;  
    import android.view.View;  
    import android.view.View.OnClickListener;  
    import android.view.ViewGroup.LayoutParams;  
    import android.view.animation.Animation;  
    import android.view.animation.Animation.AnimationListener;  
    import android.view.animation.TranslateAnimation;  
    import android.view.inputmethod.InputMethodManager;  
    import android.widget.AdapterView;  
    import android.widget.AdapterView.OnItemClickListener;  
    import android.widget.ArrayAdapter;  
    import android.widget.EditText;  
    import android.widget.ListView;  
    import android.widget.PopupWindow;  
    import android.widget.RelativeLayout;  
    import android.widget.TextView;  
    import android.widget.Toast;  
      
    /** 
     * @author J!nl!n 
     * @date 2014年11月22日 
     * @time 下午9:54:31 
     * @type Activity2.java 
     * @todo 
     */  
    public class Activity2 extends Activity implements OnClickListener, OnItemClickListener,  
            PopupWindow.OnDismissListener {  
        private TextView tv_top_title;  
          
        private ListView listView;  
        private View headerView;  
        private TextView tv_search;  
      
        // show and hide  
        private RelativeLayout mainLayout;  
        private RelativeLayout titleBarLayout;  
        private int moveHeight;  
        private int statusBarHeight;  
      
        // search popupwindow  
        private PopupWindow popupWindow;  
        private View searchView;  
        private EditText searchEditText;  
        private TextView cancelTextView;  
        private ListView filterListView;  
        private View alphaView;  
      
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.activity2);  
      
            tv_top_title = (TextView) findViewById(R.id.tv_top_title);  
            tv_top_title.setText("我是第二种");  
            initCtrl();  
        }  
      
        @Override  
        public void onClick(View view) {  
            switch (view.getId()) {  
            case R.id.tv_search:  
                showSearchBar();  
                break;  
            case R.id.popup_window_tv_cancel:  
                dismissPopupWindow();  
                break;  
            case R.id.popup_window_v_alpha:  
                dismissPopupWindow();  
                break;  
            }  
        }  
      
        @Override  
        public void onItemClick(AdapterView<?> viewGroup, View view, int position, long arg3) {  
            switch (viewGroup.getId()) {  
            case R.id.lv:  
                if (position == 0) {  
                    showSearchBar();  
                }  
                break;  
            case R.id.popup_window_lv:  
                Toast.makeText(Activity2.this, "click-" + position, Toast.LENGTH_LONG).show();  
                break;  
            }  
        }  
      
        @Override  
        public void onDismiss() {  
            resetUI();  
        }  
      
        private void initCtrl() {  
            listView = (ListView) findViewById(R.id.lv);  
            LayoutInflater mInflater = LayoutInflater.from(this);  
            headerView = mInflater.inflate(R.layout.activity2_3_search, null);  
            listView.addHeaderView(headerView);  
            listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getData()));  
            listView.setOnItemClickListener(this);  
            tv_search = (TextView) headerView.findViewById(R.id.tv_search);  
            tv_search.setOnClickListener(this);  
      
            mainLayout = (RelativeLayout) findViewById(R.id.main);  
            titleBarLayout = (RelativeLayout) findViewById(R.id.title_bar_layout);  
      
            searchView = mInflater.inflate(R.layout.popup_window_search, null);  
            searchEditText = (EditText) searchView.findViewById(R.id.popup_window_et_search);  
            searchEditText.setFocusable(true);  
            searchEditText.addTextChangedListener(new TextWatcher() {  
      
                @Override  
                public void onTextChanged(CharSequence s, int start, int before, int count) {  
                    if (s.toString().equals("")) {  
                        alphaView.setVisibility(View.VISIBLE);  
                        filterListView.setVisibility(View.GONE);  
                    } else {  
                        alphaView.setVisibility(View.GONE);  
                        filterListView.setVisibility(View.VISIBLE);  
                    }  
                }  
      
                @Override  
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {  
                }  
      
                @Override  
                public void afterTextChanged(Editable s) {  
                }  
            });  
      
            cancelTextView = (TextView) searchView.findViewById(R.id.popup_window_tv_cancel);  
            cancelTextView.setOnClickListener(this);  
            filterListView = (ListView) searchView.findViewById(R.id.popup_window_lv);  
            filterListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getData2()));  
            filterListView.setOnItemClickListener(this);  
            alphaView = searchView.findViewById(R.id.popup_window_v_alpha);  
            alphaView.setOnClickListener(this);  
      
            popupWindow = new PopupWindow(searchView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);  
            popupWindow.setFocusable(true);  
            popupWindow.setOutsideTouchable(true);  
            popupWindow.setTouchable(true);  
            popupWindow.setBackgroundDrawable(new BitmapDrawable());  
            popupWindow.setOnDismissListener(this);  
        }  
      
        private List<String> getData() {  
            List<String> data = new ArrayList<String>();  
            for (int i = 0; i < 100; i++) {  
                data.add("测试数据" + i);  
            }  
            return data;  
        }  
      
        private List<String> getData2() {  
            List<String> data = new ArrayList<String>();  
            for (int i = 0; i < 100; i++) {  
                data.add("搜索数据" + i);  
            }  
            return data;  
        }  
      
        private void getStatusBarHeight() {  
            Rect frame = new Rect();  
            getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);  
            statusBarHeight = frame.top;  
        }  
      
        private void showSearchBar() {  
            getStatusBarHeight();  
            moveHeight = titleBarLayout.getHeight();  
            Animation translateAnimation = new TranslateAnimation(0, 0, 0, -moveHeight);  
            translateAnimation.setDuration(300);  
            mainLayout.startAnimation(translateAnimation);  
            translateAnimation.setAnimationListener(new AnimationListener() {  
      
                @Override  
                public void onAnimationStart(Animation arg0) {  
                }  
      
                @Override  
                public void onAnimationRepeat(Animation arg0) {  
      
                }  
      
                @Override  
                public void onAnimationEnd(Animation arg0) {  
                    TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0);  
                    mainLayout.setAnimation(anim);  
                    titleBarLayout.setVisibility(View.GONE);  
                    titleBarLayout.setPadding(0, -moveHeight, 0, 0);  
      
                    popupWindow.showAtLocation(mainLayout, Gravity.CLIP_VERTICAL, 0, statusBarHeight);  
                    openKeyboard();  
                }  
            });  
      
        }  
      
        private void openKeyboard() {  
            Timer timer = new Timer();  
            timer.schedule(new TimerTask() {  
                @Override  
                public void run() {  
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
                    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);  
                }  
            }, 0);  
        }  
      
        private void dismissPopupWindow() {  
            if (popupWindow != null && popupWindow.isShowing()) {  
                popupWindow.dismiss();  
            }  
        }  
      
        private void resetUI() {  
            titleBarLayout.setPadding(0, 0, 0, 0);  
            titleBarLayout.setVisibility(View.VISIBLE);  
            Animation translateAnimation = new TranslateAnimation(0, 0, -moveHeight, 0);  
            translateAnimation.setDuration(300);  
            mainLayout.startAnimation(translateAnimation);  
            translateAnimation.setAnimationListener(new AnimationListener() {  
      
                @Override  
                public void onAnimationStart(Animation arg0) {  
      
                }  
      
                @Override  
                public void onAnimationRepeat(Animation arg0) {  
      
                }  
      
                @Override  
                public void onAnimationEnd(Animation arg0) {  
                    TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0);  
                    mainLayout.setAnimation(anim);  
                    // titleBarLayout.setPadding(0, 0, 0, 0);  
      
                }  
            });  
        }  
      
    }  

第三种

    /**********************************************************  
     * @文件名称:Activity3.java  
     * @创建时间:2014年11月22日 下午9:54:53 
     * @修改历史:2014年11月22日 
     **********************************************************/  
    package com.jinlin.searchview;  
      
    import java.util.ArrayList;  
    import java.util.List;  
    import java.util.Timer;  
    import java.util.TimerTask;  
      
    import android.app.Activity;  
    import android.content.Context;  
    import android.graphics.Rect;  
    import android.graphics.drawable.BitmapDrawable;  
    import android.os.Bundle;  
    import android.text.Editable;  
    import android.text.TextWatcher;  
    import android.view.Gravity;  
    import android.view.LayoutInflater;  
    import android.view.View;  
    import android.view.View.OnClickListener;  
    import android.view.ViewGroup.LayoutParams;  
    import android.view.animation.Animation;  
    import android.view.animation.Animation.AnimationListener;  
    import android.view.animation.TranslateAnimation;  
    import android.view.inputmethod.InputMethodManager;  
    import android.widget.AdapterView;  
    import android.widget.AdapterView.OnItemClickListener;  
    import android.widget.ArrayAdapter;  
    import android.widget.EditText;  
    import android.widget.LinearLayout;  
    import android.widget.ListView;  
    import android.widget.PopupWindow;  
    import android.widget.RelativeLayout;  
    import android.widget.TextView;  
    import android.widget.Toast;  
      
    /** 
     * @author J!nl!n 
     * @date 2014年11月22日 
     * @time 下午9:54:53 
     * @type Activity3.java 
     * @todo 
     */  
    public class Activity3 extends Activity implements OnClickListener, OnItemClickListener, PopupWindow.OnDismissListener {  
        private TextView tv_top_title;  
          
        private ListView listView;  
        private TextView tv_search;  
      
        // show and hide  
        private LinearLayout mainLayout;  
        private RelativeLayout titleBarLayout;  
        private int moveHeight;  
        private int statusBarHeight;  
      
        // search popupwindow  
        private PopupWindow popupWindow;  
        private View searchView;  
        private EditText searchEditText;  
        private TextView cancelTextView;  
        private ListView filterListView;  
        private View alphaView;  
      
        @Override  
        protected void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.activity3);  
      
            tv_top_title = (TextView) findViewById(R.id.tv_top_title);  
            tv_top_title.setText("我是第三种");  
            initCtrl();  
        }  
      
        @Override  
        public void onClick(View view) {  
            switch (view.getId()) {  
            case R.id.tv_search:  
                showSearchBar();  
                break;  
            case R.id.popup_window_tv_cancel:  
                dismissPopupWindow();  
                break;  
            case R.id.popup_window_v_alpha:  
                dismissPopupWindow();  
                break;  
            }  
        }  
      
        @Override  
        public void onItemClick(AdapterView<?> viewGroup, View view, int position, long arg3) {  
            switch (viewGroup.getId()) {  
            case R.id.lv:  
                if (position == 0) {  
                    showSearchBar();  
                }  
                break;  
            case R.id.popup_window_lv:  
                Toast.makeText(Activity3.this, "click-" + position, Toast.LENGTH_LONG).show();  
                break;  
            }  
        }  
      
        @Override  
        public void onDismiss() {  
            resetUI();  
        }  
      
        private void initCtrl() {  
            listView = (ListView) findViewById(R.id.lv);  
      
            LayoutInflater mInflater = LayoutInflater.from(this);  
      
            listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getData()));  
            listView.setOnItemClickListener(this);  
      
            tv_search = (TextView) findViewById(R.id.tv_search);  
            tv_search.setOnClickListener(this);  
      
            mainLayout = (LinearLayout) findViewById(R.id.mainLayout);  
            titleBarLayout = (RelativeLayout) findViewById(R.id.title_bar_layout);  
      
            searchView = mInflater.inflate(R.layout.popup_window_search, null);  
            searchEditText = (EditText) searchView.findViewById(R.id.popup_window_et_search);  
            searchEditText.setFocusable(true);  
            searchEditText.addTextChangedListener(new TextWatcher() {  
      
                @Override  
                public void onTextChanged(CharSequence s, int start, int before, int count) {  
                    if (s.toString().equals("")) {  
                        alphaView.setVisibility(View.VISIBLE);  
                        filterListView.setVisibility(View.GONE);  
                    } else {  
                        alphaView.setVisibility(View.GONE);  
                        filterListView.setVisibility(View.VISIBLE);  
                    }  
                }  
      
                @Override  
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {  
                }  
      
                @Override  
                public void afterTextChanged(Editable s) {  
                }  
            });  
      
            cancelTextView = (TextView) searchView.findViewById(R.id.popup_window_tv_cancel);  
            cancelTextView.setOnClickListener(this);  
            filterListView = (ListView) searchView.findViewById(R.id.popup_window_lv);  
            filterListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getData2()));  
            filterListView.setOnItemClickListener(this);  
            alphaView = searchView.findViewById(R.id.popup_window_v_alpha);  
            alphaView.setOnClickListener(this);  
      
            popupWindow = new PopupWindow(searchView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);  
            popupWindow.setFocusable(true);  
            popupWindow.setOutsideTouchable(true);  
            popupWindow.setTouchable(true);  
            popupWindow.setBackgroundDrawable(new BitmapDrawable());  
            popupWindow.setOnDismissListener(this);  
        }  
      
        private List<String> getData() {  
            List<String> data = new ArrayList<String>();  
            for (int i = 0; i < 100; i++) {  
                data.add("测试数据" + i);  
            }  
            return data;  
        }  
      
        private List<String> getData2() {  
            List<String> data = new ArrayList<String>();  
            for (int i = 0; i < 100; i++) {  
                data.add("搜索数据" + i);  
            }  
            return data;  
        }  
      
        private void getStatusBarHeight() {  
            Rect frame = new Rect();  
            getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);  
            statusBarHeight = frame.top;  
        }  
      
        private void showSearchBar() {  
            getStatusBarHeight();  
            moveHeight = titleBarLayout.getHeight();  
            Animation translateAnimation = new TranslateAnimation(0, 0, 0, -moveHeight);  
            translateAnimation.setDuration(300);  
            mainLayout.startAnimation(translateAnimation);  
            translateAnimation.setAnimationListener(new AnimationListener() {  
      
                @Override  
                public void onAnimationStart(Animation arg0) {  
                }  
      
                @Override  
                public void onAnimationRepeat(Animation arg0) {  
      
                }  
      
                @Override  
                public void onAnimationEnd(Animation arg0) {  
                    TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0);  
                    mainLayout.setAnimation(anim);  
                    titleBarLayout.setVisibility(View.GONE);  
                    titleBarLayout.setPadding(0, -moveHeight, 0, 0);  
      
                    popupWindow.showAtLocation(mainLayout, Gravity.CLIP_VERTICAL, 0, statusBarHeight);  
                    openKeyboard();  
                }  
            });  
      
        }  
      
        private void openKeyboard() {  
            Timer timer = new Timer();  
            timer.schedule(new TimerTask() {  
                @Override  
                public void run() {  
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);  
                    imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);  
                }  
            }, 0);  
        }  
      
        private void dismissPopupWindow() {  
            if (popupWindow != null && popupWindow.isShowing()) {  
                popupWindow.dismiss();  
            }  
        }  
      
        private void resetUI() {  
            titleBarLayout.setPadding(0, 0, 0, 0);  
            titleBarLayout.setVisibility(View.VISIBLE);  
            Animation translateAnimation = new TranslateAnimation(0, 0, -moveHeight, 0);  
            translateAnimation.setDuration(300);  
            mainLayout.startAnimation(translateAnimation);  
            translateAnimation.setAnimationListener(new AnimationListener() {  
      
                @Override  
                public void onAnimationStart(Animation arg0) {  
      
                }  
      
                @Override  
                public void onAnimationRepeat(Animation arg0) {  
      
                }  
      
                @Override  
                public void onAnimationEnd(Animation arg0) {  
                    TranslateAnimation anim = new TranslateAnimation(0, 0, 0, 0);  
                    mainLayout.setAnimation(anim);  
                    // titleBarLayout.setPadding(0, 0, 0, 0);  
      
                }  
            });  
        }  
      
    }  

githib地址:https://github.com/5peak2me/QQSearchView

源码飞机票

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

两种方式实现类似qq搜索的切换 的相关文章

  • 天平(Not so Mobile)

    Not so Mobile Time Limit 3000MS Memory Limit Unknown 64bit IO Format lld amp llu Submit Status Description Before being
  • 下落的树叶(The Falling Leaves)

    The Falling Leaves Time Limit 3000MS Memory Limit Unknown 64bit IO Format lld amp llu Submit Status Description Each yea
  • 四分树(Quadtrees)

    Quadtrees Time Limit 3000MS Memory Limit Unknown 64bit IO Format lld amp llu Submit Status Description A quadtree is a r
  • 油田(Oil Deposits)

    Oil Deposits Time Limit 3000MS Memory Limit Unknown 64bit IO Format lld amp llu Submit Status Description The GeoSurvCom
  • Abbott的复仇(Abbott's Revenge)

    Abbott 39 s Revenge Time limit 3 000 seconds Abbott s Revenge Abbott s Revenge The 1999 World FinalsContest included a p
  • rockchip rk3568 openwrt修改根文件系统分区

    rk3568的openwrt根文件系统分区大小如何修改 xff1f 1 rootfs大小取决于rk356x config的配置 xff0c 默认CONFIG TARGET ROOTFS PARTSIZE 61 512 xff0c 如果需要修
  • 除法(Division)

    Division Time Limit 3000MS Memory Limit Unknown 64bit IO Format lld amp llu Submit Status Description Write a program th
  • 最大乘积(Maximum Product)

    Maximum Product Time Limit 3000MS Memory Limit Unknown 64bit IO Format lld amp llu Submit Status Description Problem D M
  • 分数拆分(Fractions Again?!)

    Fractions Again Time Limit 3000MS Memory Limit Unknown 64bit IO Format lld amp llu Submit Status Description Problem A F
  • 二叉树(Tree Recovery)

    Tree Recovery Time Limit 3000MS Memory Limit Unknown 64bit IO Format lld amp llu Submit Status Description Little Valent
  • 骑士的移动(Knight Moves)

    Knight Moves Time Limit 3000MS Memory Limit Unknown 64bit IO Format lld amp llu Submit Status Description A friend of yo
  • 单词(Play On Words)

    分析 首先需对欧拉道路有所了解 存在欧拉道路的充分条件 xff1a 对于无向图而言 xff0c 如果一个无向图是连通的 xff0c 且最多只有两个奇点 xff08 顶点的度数为奇数 xff09 xff0c 则一定存在欧拉道路 如果有两个奇点
  • 成语接龙(Idiomatic Phrases Game)

    Idiomatic Phrases Game Problem Description Tom is playing a game called Idiomatic Phrases Game An idiom consists of seve
  • DijKstra算法(单源最短路径)

    原文转载自 xff1a 梦醒潇湘love 转载原文是为了方便自己学习 xff0c 也希望能让更多读者在需要的情况下学到更多的知识 Dijkstra xff08 迪杰斯特拉 xff09 算法是典型的最短路径路由算法 xff0c 用于计算一个节
  • Floyd算法(最短路径)

    Floyd 算法允许图中有带负权值的边 xff0c 但不许有包含带负权值的边组成的回路 原文转载自 xff1a 梦醒潇湘love 上一篇文章我们通过迪杰斯特拉算法解决了从某个源点到其余各顶点的最短路径问题 从循环嵌套很容易得到此算法的时间复
  • 最爱的城市

    最爱的城市 时间限制 xff1a 1 秒 内存限制 xff1a 32 兆 特殊判题 xff1a 否 标签 Floyd最短路径 题目描述 一天小明捧着一本世界地图在看 xff0c 突然小明拿起笔 xff0c 将他最爱的那些城市标记出来 xff
  • Docker中配置Nginx多域名配置多个应用

    注意容器中是一个被隔离的空间 xff0c 可以理解为一个独立的服务器 xff0c 所以在做反向代理的时候 xff0c nginx配置不能使用localhost xff0c 可以使用link方式去访问其他容器 nginxa container
  • 八皇后问题(回溯法)

    八皇后问题 xff08 源于 刘汝佳的 算法竞赛入门经典 xff08 第2版 xff09 xff09 在棋盘上放置8个皇后 xff0c 使得它们互不攻击 xff0c 此时每个皇后的攻击范围为同行同列和同对角线 xff0c 要求找出所有解 x
  • 大整数的乘法

    大整数的乘法 xff08 这里主要讨论的是两个较大的数相乘的效率问题 xff0c 实际上并不是真正意义上的大数相乘 在java中有个BigInteger类已经可以储存大数 xff0c 并提供了大数相乘的方法了 xff09 分析 首先 xff

随机推荐

  • 2的次幂表示

    2的次幂表示 时间限制 xff1a 1 0s 内存限制 xff1a 512 0MB 问题描述 任何一个正整数都可以用2进制表示 xff0c 例如 xff1a 137的2进制表示为10001001 将这种2进制表示写成2的次幂的和的形式 xf
  • 扑克序列

    扑克序列 题目描述 标题 xff1a 扑克序列 A A 2 2 3 3 4 4 xff0c 一共4对扑克牌 请你把它们排成一行 要求 xff1a 两个A中间有1张牌 xff0c 两个2之间有2张牌 xff0c 两个3之间有3张牌 xff0c
  • 分糖果

    分糖果 时间限制 xff1a 1 0s 内存限制 xff1a 256 0MB 问题描述 有n个小朋友围坐成一圈 老师给每个小朋友随机发偶数个糖果 xff0c 然后进行下面的游戏 xff1a 每个小朋友都把自己的糖果分一半给左手边的孩子 一轮
  • 最长公共子序列(LCS)

    最长公共子序列LCS问题 给定2个序列X和Y xff0c 当另一序列Z既是X的子序列又是Y的子序列时 xff0c 称Z是序列X和Y的公共子序列 给定X 61 x1 x2 xm 和Y 61 y1 y2 yn xff0c 请找出X和Y的最长公共
  • 0-1背包问题

    0 1背包问题 甲欲出去旅游 xff0c 可携带20 公斤的行李 xff0c 已知甲想带的 5 件行李的重量及其在旅行中产生的效益如下表所示 xff1a 行李编号 I II III IV V 重量 千克 6 4 8 8 4 行李效益 8 4
  • 旅行售货员问题

    旅行售货员问题 题目 某售货员要到4 个城市去推销商品 xff0c 已知各城市之间的路程 xff0c 如右图所示 请问他应该如何选定一条从城市 1 出发 xff0c 经过每个城市一遍 xff0c 最后回到城市 1 的路线 xff0c 使得总
  • https网页加载http资源时不显示图片,报错解决方案

    https网页加载http资源时不显示图片 xff0c 报错解决方案 自动将http的不安全请求升级为https静态文件放置本地反向代理请求http资源 加载http资源时会报错 xff1a 自动将http的不安全请求升级为https 页面
  • 数独游戏

    数独游戏 题目 九宫格是在81个格子 9 9 中 xff0c 要满足以下条件 xff1a xff08 1 xff09 每个横行和竖列中的9个格子都包含数字1 xff5e 9 xff0c 且不重复 xff1b xff08 2 xff09 每个
  • 静态内部类和普通内部类

    两种内部类 Java的内部类有两种 xff0c 一种是静态内部类 xff0c 另一种是普通内部类 xff0c 普通内部类可以获得外部对象的引用 xff0c 所以在普通内部类能够访问外部对象的成员变量 xff0c 也就能够使用外部类的资源 x
  • 迷宫老鼠游戏

    迷宫老鼠游戏 题目 以一个m n的长方阵表示迷宫 xff0c 0 和 1 分别表示迷宫中的通路和障碍 请设计一个算法 xff0c 对任意设定的迷宫 xff0c 求出一条从入口到出口的通路 xff0c 或得出没有通路的结论 xff1b 如果有
  • java通过JDBC链接SQLServer2012

    下面请一字一句地看 xff0c 一遍就设置成功 xff0c 比你设置几十遍失败 xff0c 费时会少得多 首先 xff0c 在连接数据库之前必须保证SQL Server 2012是采用SQL Server身份验证方式而不是windows身份
  • 完整java开发中JDBC连接数据库代码和步骤

    转载自 xff1a Hongten JDBC连接数据库 创建一个以JDBC连接数据库的程序 xff0c 包含7 个步骤 xff1a 1 加载JDBC驱动程序 xff1a 在连接数据库之前 xff0c 首先要加载想要连接的数据库的驱动到JVM
  • 浅析网站 APP 登录界面设计

    无论网页或是移动APP的设计 xff0c 很重要的一点是如何能在小而美和功能复杂性之间找到平衡点 本文就移动APP表单设计进行浅析 xff0c 看设计师是如何在设计与交互体验之间做到小而美的平衡 一 极致的减法 这是一个异于常规设计思路而得
  • Android应用开发EditText文本内容变化监听方法

    package com google import android app Activity import android os Bundle import android text Editable import android text
  • Android背景渐变色(shape,gradient)

    转载自 xff1a http l62s iteye com blog 1659433 Android设置背景 色可以通过在res drawable里定义一个xml 如下 xff1a 代码 xml代码 xff1a lt xml version
  • Android 自定义CheckBox 样式

    转载自 xff1a http www open open com lib view open1392187282067 html 有些时候需要根据项目需求自定义CheckBox 的样式 xff0c 步骤如下 xff1a 1 首先在drawa
  • 定制个性化的 Android Checkbox 图标

    首发来自 http blog csdn net garretly 转载注明出处 先大概说一下 这里用到的技术比较简单没有多大的技术含量 关键是大家如何去理解 以及自我更新 好了 这里上代码 在 工程目录下 gt res gt drawabl
  • 解决ssl connect error问题

    curl版本过低 xff0c 升级curl php重新编译 xff0c 指定curl库解决
  • RadioGroup以及RadioButton自定义样式的使用

    转载自 xff1a RadioGroup以及RadioButton自定义样式的使用 RadioButton从字面上就可以很清楚的知道它是单选按钮 xff0c 它与RadioGroup配套时候 通常我们在开发中需要自定义RadioButton
  • 两种方式实现类似qq搜索的切换

    转载自 xff1a 点击打开链接 http www csdn net tag searchview qq的搜索功能在点击搜索框时整个页面上移 xff0c 出现透明布局 该效果是模仿iOS实现的 xff0c 但是在Android也是很容易实现