简易模仿手机拨号盘浮在ListView之上并且展开,折叠效果

2013-12-24 16:56:45

有时候可以看到很多手机会将Call log list和Dailer放在同一个页面中,同时Dialer是可以折叠、打开的,自己做了一个Demo,能实现这种效果,简易版的,就当做个笔记吧。

里面用到了简单的动画,不过布局稍显特殊。

废话不多说,直接上代码:

 1 public class TestActivity extends Activity implements

 2         Animation.AnimationListener {

 3 

 4     private ListView mListView;

 5 

 6     private Animation mDialpadOutAnim;

 7     private Animation mDialpadInAnim;

 8     private View mDialpad;

 9     private View mTwelveKey;

10     private boolean mClosed;

11 

12     private String[] list;

13 

14     @Override

15     protected void onCreate(Bundle savedInstanceState) {

16         super.onCreate(savedInstanceState);

17         setContentView(R.layout.activity_test);

18         mDialpad = findViewById(R.id.dialpad_container);

19         mListView = (ListView) findViewById(android.R.id.list);

20         initListView();

21     }

22 

23     private void initListView() {

24         int i = 0;

25         list = new String[10];

26         StringBuilder sb = new StringBuilder("Test");

27         do {

28             list[i] = (sb.append(i + "").toString());

29             i++;

30         } while (i < 10);

31         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,

32                 android.R.layout.simple_list_item_1, list);

33         mListView.setAdapter(adapter);

34     }

35 

36     public void onClick(View v) {

37         if (mClosed) {

38             maximizeDialpad();

39             // mListView.setVisibility(View.GONE);

40         } else {

41             minimizeDialpad();

42         }

43     }

44 

45     private void minimizeDialpad() {

46         mTwelveKey = findViewById(R.id.twelve_key_dialer_layout);

47         mDialpadOutAnim = AnimationUtils

48                 .loadAnimation(this, R.anim.dialpad_out);

49         mDialpadOutAnim.setAnimationListener(this);

50         mTwelveKey.startAnimation(this.mDialpadOutAnim);

51         mClosed = true;

52     }

53 

54     private void maximizeDialpad() {

55         mTwelveKey = findViewById(R.id.twelve_key_dialer_layout);

56         mDialpadInAnim = AnimationUtils.loadAnimation(this, R.anim.dialpad_in);

57         mDialpadInAnim.setAnimationListener(this);

58         mTwelveKey.startAnimation(this.mDialpadInAnim);

59         mDialpad.setVisibility(View.VISIBLE);

60         mClosed = false;

61     }

62 

63     @Override

64     public void onAnimationStart(Animation animation) {

65 

66     }

67 

68     @Override

69     public void onAnimationEnd(Animation animation) {

70         if (mClosed) {

71             mDialpad.setVisibility(View.GONE);

72         }

73     }

74 

75     @Override

76     public void onAnimationRepeat(Animation animation) {

77 

78     }

79 }

其他的布局、资源文件就不贴出来了,有兴趣的直接下载Demo源码吧。

Demo源码,猛戳这里

你可能感兴趣的:(ListView)