回答
...
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