iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 28
0
Software Development

Kotlin 2018連續開發30天系列 第 28

Kotlin 2018連續開發30天 day 28 超簡易3d gallery使用方法

導入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好像已經沒有人維護了 想使用的話可能要注意


上一篇
Kotlin 2018連續開發30天 day 27 超簡易togglebuttom使用方法
下一篇
# Kotlin 2018連續開發30天 day29 指紋辨識加上進度條
系列文
Kotlin 2018連續開發30天30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言