導入library
android {
compileSdkVersion 26
defaultConfig {
**** applicationId "com.example.likunlin.a3dgallery"****
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
同步後
XML引用
<at.technikum.mti.fancycoverflow.FancyCoverFlow
android:id="@+id/fancyCoverFlow"
android:layout_width="match_parent"
android:layout_height="match_parent"
fcf:maxRotation="45"
fcf:unselectedAlpha="0.3"
fcf:unselectedSaturation="0.0"
fcf:unselectedScale="0.4"
fcf:scaleDownGravity="0.5"/>
Activity引用完成效果
寫入adapter
class FancyCoverFlowSampleAdapter : FancyCoverFlowAdapter() {
val images = intArrayOf(R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4, R.drawable.image5, R.drawable.image6)
override fun getItem(i: Int): Int {
return images[i]
}
override fun getCoverFlowItem(position: Int, reusableView: View?, parent: ViewGroup?): View {
var imageView: ImageView? = null
if (reusableView != null) {
imageView = reusableView as ImageView
} else {
imageView = ImageView(parent!!.getContext())
imageView.scaleType = ImageView.ScaleType.CENTER_INSIDE
imageView.layoutParams = FancyCoverFlow.LayoutParams(600, 800)
}
imageView.setImageResource(this.getItem(position))
return imageView
}
override fun getItemId(i: Int): Long {
return i.toLong()
}
override fun getCount(): Int {
return images.size
}
}
使用效果
val fancyCoverFlow = this.findViewById<View>(R.id.fancyCoverFlow) as FancyCoverFlow
this.fancyCoverFlow.setAdapter(FancyCoverFlowSampleAdapter())
this.fancyCoverFlow.setUnselectedAlpha(0.2f)
this.fancyCoverFlow.setUnselectedSaturation(0.0f)
this.fancyCoverFlow.setUnselectedScale(0.5f)
this.fancyCoverFlow.setSpacing(1)
this.fancyCoverFlow.setMaxRotation(40)
this.fancyCoverFlow.setScaleDownGravity(0.3f)
this.fancyCoverFlow.setActionDistance(FancyCoverFlow.ACTION_DISTANCE_AUTO)
完成
結論
這個library好像已經沒有人維護了 想使用的話可能要注意