一个开源项目欢迎,分享给大家
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:coverflow="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/darker_gray" tools:context="it.moondroid.carousellayoutdemo.CoverFlowActivity"> <it.moondroid.coverflow.components.ui.containers.FeatureCoverFlow android:id="@+id/coverflow" android:layout_width="match_parent" android:layout_height="match_parent" coverflow:coverHeight="@dimen/cover_height" coverflow:coverWidth="@dimen/cover_width" coverflow:maxScaleFactor="1.5" coverflow:reflectionGap="0px" coverflow:rotationThreshold="0.5" coverflow:scalingThreshold="0.5" coverflow:spacing="0.6" /> <TextSwitcher android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="16dp" android:layout_alignParentBottom="true" android:layout_centerVertical="true" /> </RelativeLayout>
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<GameEntity> 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
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-17 21:33:04