回答
...
https://github.com/ludovicroland/carousel-android
摇篮
compile 'fr.rolandl:carousel:[email protected]'
Maven的
<dependency>
<groupId>fr.rolandl</groupId>
<artifactId>carousel</artifactId>
<version>1.0.1</version>
<type>aar</type>
</dependency>
由于图书馆项目
Alternati请检查此资源库并将其添加为库项目。
$ git clone https://github.com/ludovicroland/carousel-android.git 将项目导入到您最喜欢的IDE中,并将android.library.reference.1 =/path/to/carousel-android/library添加到您的project.properties中。
布局
您需要将旋转木马直接声明到布局中。
<fr.rolandl.carousel.Carousel
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/carousel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animationDuration="200"
/>
物品
的项目应该用业务对象(经典POJO)相关联,例如:
public final class Photo
implements Serializable
{
private static final long serialVersionUID = 1L;
public final String name;
public final String image;
public Photo(String name, String image)
{
this.name = name;
this.image = image;
}
}
与特定的布局,例如:
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
/>
,并应覆盖extractView和更新方法CarouselItem:
public final class PhotoItem
extends CarouselItem<Photo>
{
private ImageView image;
private TextView name;
private Context context;
public PhotoItem(Context context)
{
super(context, R.layout.item);
this.context = context;
}
@Override
public void extractView(View view)
{
image = (ImageView) view.findViewById(R.id.image);
name = (TextView) view.findViewById(R.id.name);
}
@Override
public void update(Photo photo)
{
image.setImageResource(getResources().getIdentifier(photo.image, "drawable", context.getPackageName()));
name.setText(photo.name);
}
}
适配器
你也可以创建自己的适配器,它需要在其构造业务对象的列表:
public final class MyAdapter
extends CarouselAdapter<Photo>
{
public MyAdapter(Context context, List<Photo> photos)
{
super(context, photos);
}
@Override
public CarouselItem<Photo> getCarouselItem(Context context)
{
return new PhotoItem(context);
}
}
在Activity/Fragment
在活动或使用该转盘的片段,你可以找到它的参考:
final Carousel carousel; = (Carousel) findViewById(R.id.carousel);
create your list of business objects:
final List<Photo> photos = new ArrayList<>();
photos.add(new Photo("Photo1", "fotolia_40649376"));
photos.add(new Photo("Photo2", "fotolia_40973414"));
photos.add(new Photo("Photo3", "fotolia_48275073"));
photos.add(new Photo("Photo4", "fotolia_50806609"));
photos.add(new Photo("Photo5", "fotolia_61643329"));
创建适配器的一个实例:
final CarouselAdapter adapter = adapter = new MyAdapter(this, photos);
carousel.setAdapter(adapter);
adapter.notifyDataSetChanged();
听众
您还可以使用旋转木马上的一些听众。
的OnItemClickListener:
carousel.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(CarouselBaseAdapter<?> carouselBaseAdapter, View view, int position, long id)
{
Toast.makeText(getApplicationContext(), "The item '" + position + "' has been clicked", Toast.LENGTH_SHORT).show();
carousel.scrollToChild(position);
}
});
的OnItemLongClickListener:
carousel.setOnItemLongClickListener(new OnItemLongClickListener()
{
@Override
public boolean onItemLongClick(CarouselBaseAdapter<?> carouselBaseAdapter, View view, int position, long id)
{
Toast.makeText(getApplicationContext(), "The item '" + position + "' has been long clicked", Toast.LENGTH_SHORT).show();
carousel.scrollToChild(position);
return false;
}
});
也看到这个链接..
谢谢你的回应呃。 Arjun saini ...让我试试这个。将发布关于回应 – bharatkumar
作品像魅力。谢谢。 – bharatkumar
欢迎@bharatkumar ..... –
我们需要创建2 XML文件,1)绘制椭圆形和2)布局设计。创建2个以下的文件并将其添加到您的项目中。
drwbl_ovalview.xml(RES - >绘制)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="5dp"
android:color="#5EC7F1" />
</shape>
activity_main.xml中(RES - >布局)的
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_margin="16dp">
<ImageView
android:id="@+id/imgvw_ovalview"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_margin="25dp"
android:src="@drawable/drwbl_ovalview"
android:contentDescription="Images"/>
<ImageView
android:id="@+id/imgvw_yahoo"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/yahoo_icon"
android:contentDescription="Yahoo images"/>
<ImageView
android:id="@+id/imgvw_messenger"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
android:src="@drawable/messenger_icon"
android:contentDescription="Messenger images"/>
<ImageView
android:id="@+id/imgvw_google"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="@drawable/google_icon"
android:contentDescription="Google images"/>
<ImageView
android:id="@+id/imgvw_facebook"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:src="@drawable/facebook_icon"
android:contentDescription="Facbook image"/>
</RelativeLayout>
</LinearLayout>
谢谢你的回答Jaldeep Asodariya。但我想你让我的查询错误了。我正在寻找一个解决方案,如画廊视角中所述。 – bharatkumar
感谢@bharatkumar,并为误会感到抱歉。 –
- 1. Android布局设计
- 2. Android设计布局
- 3. Android:可滚动图片库布局
- 4. Android设计支持库ViewPager片段与协调器布局
- 5. Android的布局中的布局设计
- 6. Android的视图布局设计帮助
- 7. android中的布局设计
- 8. 布局设计在android
- 9. android布局设计工具
- 10. Eclipse Android布局设计
- 11. Android的布局设计
- 12. Android设计布局比较
- 13. 使用TableLayout和图库在Android中设计布局
- 14. 如何将Appbar(Android设计)布局应用于碎片?
- 15. Android XML布局 - 带有TextView的图片
- 16. WPF - 布局设计
- 17. Android的布局设计帮助
- 18. Android正确的布局设计
- 19. 更改Android微调器布局/设计
- 20. Android的工作室布局设计
- 21. 布局设计中的麻烦Android
- 22. Mono for Android - 布局设计器问题
- 23. Android:如何设计此布局
- 24. Android。帮助运行时布局设计。
- 25. android如何设计此布局
- 26. Android材质设计抽屉布局
- 27. Android设计布局ListItem RecyclerView Horizontal
- 28. 为android设计更好的布局?
- 29. Android布局设计特定自定义
- 30. 如何在android中设计布局?
搜索Cricular旋转木马的Android ......你会得到答案.... – karan
[3D Carousel在Android](http://stackoverflow.com/questions/20883849/3d-carousel-in-android) – karan