Android新组件应用

  1. CheckedTextView替代LineaLayout + TextView + ImageView 构造单选项
  2. Chronometer替代RxJava.interval + TextView
  3. StackView类似Android的多任务的布局
  4. QuickContactBadge 图片,点击会自动链接通讯录
  5. Space代替margin,因为onDraw()方法为空,所以不会渲染,包括事件处理都无效
  6. TextClock时间显示
  7. ToggleButton配合android:button="@drawable/sel"可以实现Switch效果

    //去除右下角小三角图标
    quickContactBadge.assignContactFromPhone("13012345678", false)
    val f = quickContactBadge::class.java.getDeclaredField("mOverlay")
    f.isAccessible = true
    f.set(quickContactBadge, null)
  8. TextSwitcher替代ViewFlipper实现滚动条效果

    textSwitcher.setFactory {
        val tv = TextView(this@MainActivity)
        tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16.0f)
        tv.setTextColor(Color.RED)
        return@setFactory tv
    }
    textSwitcher.inAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_in);
    textSwitcher.outAnimation = AnimationUtils.loadAnimation(this, R.anim.anim_out);
    Observable.interval(1000L, 3000L, TimeUnit.MILLISECONDS)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe {
                textSwitcher.setText((Random().nextInt()).toString())
            }

    anim_in:

    <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:fillAfter="true"
         android:shareInterpolator="false"
         android:zAdjustment="top">
        <translate
            android:duration="3000"
            android:fromYDelta="100%p"
            android:toYDelta="0"/>
    </set>

    anim_out:

    <set xmlns:android="http://schemas.android.com/apk/res/android"
         android:fillAfter="true"
         android:shareInterpolator="false"
         android:zAdjustment="top">
        <translate
            android:duration="3000"
            android:fromYDelta="0"
            android:toYDelta="-100%p"/>
    </set>
  9. PopupMenu类似QQ的右上角”+”效果

猜你喜欢

转载自blog.csdn.net/riqthen/article/details/81947552