一个开源项目欢迎。分享给大家
package it.moondroid.coverflowdemo;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewSwitcher;
import java.util.ArrayList;
import it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow;
public class CoverFlowActivity extends Activity {
private FeatureCoverFlow mCoverFlow;
private CoverFlowAdapter mAdapter;
private ArrayList mData = new ArrayList<>(0);
private TextSwitcher mTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_coverflow);
mData.add(new GameEntity(R.drawable.image_1, R.string.title1));
mData.add(new GameEntity(R.drawable.image_2, R.string.title2));
mData.add(new GameEntity(R.drawable.image_3, R.string.title3));
mData.add(new GameEntity(R.drawable.image_4, R.string.title4));
mTitle = (TextSwitcher) findViewById(R.id.title);
mTitle.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
LayoutInflater inflater = LayoutInflater.from(CoverFlowActivity.this);
TextView textView = (TextView) inflater.inflate(R.layout.item_title, null);
return textView;
}
});
Animation in = AnimationUtils.loadAnimation(this, R.anim.slide_in_top);
Animation out = AnimationUtils.loadAnimation(this, R.anim.slide_out_bottom);
mTitle.setInAnimation(in);
mTitle.setOutAnimation(out);
mAdapter = new CoverFlowAdapter(this);
mAdapter.setData(mData);
mCoverFlow = (FeatureCoverFlow) findViewById(R.id.coverflow);
mCoverFlow.setAdapter(mAdapter);
mCoverFlow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view, int position, long id) {
Toast.makeText(CoverFlowActivity.this,
getResources().getString(mData.get(position).titleResId),
Toast.LENGTH_SHORT).show();
}
});
mCoverFlow.setOnScrollPositionListener(new FeatureCoverFlow.OnScrollPositionListener() {
@Override
public void onScrolledToPosition(int position) {
mTitle.setText(getResources().getString(mData.get(position).titleResId));
}
@Override
public void onScrolling() {
mTitle.setText("");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_coverflow_activity, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
代码下载:
http://download.csdn.net/detail/jingwen3699/8937523