2013-12-24 16:56:45
有时候可以看到很多手机会将Call log list和Dailer放在同一个页面中,同时Dialer是可以折叠、打开的,自己做了一个Demo,能实现这种效果,简易版的,就当做个笔记吧。
里面用到了简单的动画,不过布局稍显特殊。
废话不多说,直接上代码:
public class TestActivity extends Activity implements
Animation.AnimationListener { private ListView mListView; private Animation mDialpadOutAnim;
private Animation mDialpadInAnim;
private View mDialpad;
private View mTwelveKey;
private boolean mClosed; private String[] list; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
mDialpad = findViewById(R.id.dialpad_container);
mListView = (ListView) findViewById(android.R.id.list);
initListView();
} private void initListView() {
int i = 0;
list = new String[10];
StringBuilder sb = new StringBuilder("Test");
do {
list[i] = (sb.append(i + "").toString());
i++;
} while (i < 10);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, list);
mListView.setAdapter(adapter);
} public void onClick(View v) {
if (mClosed) {
maximizeDialpad();
// mListView.setVisibility(View.GONE);
} else {
minimizeDialpad();
}
} private void minimizeDialpad() {
mTwelveKey = findViewById(R.id.twelve_key_dialer_layout);
mDialpadOutAnim = AnimationUtils
.loadAnimation(this, R.anim.dialpad_out);
mDialpadOutAnim.setAnimationListener(this);
mTwelveKey.startAnimation(this.mDialpadOutAnim);
mClosed = true;
} private void maximizeDialpad() {
mTwelveKey = findViewById(R.id.twelve_key_dialer_layout);
mDialpadInAnim = AnimationUtils.loadAnimation(this, R.anim.dialpad_in);
mDialpadInAnim.setAnimationListener(this);
mTwelveKey.startAnimation(this.mDialpadInAnim);
mDialpad.setVisibility(View.VISIBLE);
mClosed = false;
} @Override
public void onAnimationStart(Animation animation) { } @Override
public void onAnimationEnd(Animation animation) {
if (mClosed) {
mDialpad.setVisibility(View.GONE);
}
} @Override
public void onAnimationRepeat(Animation animation) { }
}
其他的布局、资源文件就不贴出来了,有兴趣的直接下载Demo源码吧。