小编kik*_*la2的帖子

Kotlin android 智能转换为“BottomSheetBehavior”应用程序崩溃

我这样做:

private fun initComponent() {
        // get the bottom sheet view
        val llBottomSheet = findViewById<View>(R.id.bottom_sheet) as LinearLayout

        // init the bottom sheet behavior
        bottomSheetBehavior = BottomSheetBehavior.from(llBottomSheet)

        // change the state of the bottom sheet
        bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED)

        // set callback for changes
        bottomSheetBehavior.setBottomSheetCallback(object : BottomSheetCallback() {
            override fun onStateChanged(bottomSheet: View, newState: Int) {}
            override fun onSlide(bottomSheet: View, slideOffset: Float) {}
        })

}
Run Code Online (Sandbox Code Playgroud)

当我启动我的应用程序时,该应用程序崩溃了:

bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED)
Run Code Online (Sandbox Code Playgroud)

这是一个日志:

Smart cast to 'BottomSheetBehavior<LinearLayout!>!' is impossible, because 'bottomSheetBehavior' is a mutable property that could have been changed …
Run Code Online (Sandbox Code Playgroud)

android kotlin

2
推荐指数
1
解决办法
3130
查看次数

CardView 移除边框

我也想删除 cardView 上的边框。我尝试将 elavation 设置为 0 dp ,将 app:cardPreventCornerOverlap 设置为 false 并将 app:cardUseCompatPadding 设置为 true ,但我无法从 CardView 中删除边框,这是我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@android:color/transparent"
    android:orientation="vertical">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/IMKAWhite"
        android:layout_gravity="center"
        app:cardPreventCornerOverlap="false"
        app:cardUseCompatPadding="true"
        android:elevation="0dp">

        <RelativeLayout
            android:id="@+id/card"
            android:background="@color/IMKAWhite"
            android:layout_width="150sp"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="150sp"
                android:layout_height="150sp"
                android:id="@+id/profile_photo"
                android:adjustViewBounds="true"
                android:background="@color/colorPrimary"
                android:layout_centerHorizontal="true" />

            <TextView
                android:layout_below="@+id/profile_photo"
                android:id="@+id/profile_name"
                android:layout_marginTop="10sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:textStyle="bold"
                android:textColor="@color/background_tutorial"
                android:textSize="@dimen/text_dp_25"
                android:gravity="center"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/bt_edit_profile"
                android:layout_below="@+id/profile_name"
                android:layout_marginTop="@dimen/text_dp_25"
                android:layout_centerHorizontal="true"
                android:textSize="@dimen/text_dp_16"
                android:padding="5sp"
                android:textColor="@color/background_tutorial"
                android:background="@drawable/ic_bt_edit"
                android:text="@string/edit_profile"
                android:gravity="center" /> …
Run Code Online (Sandbox Code Playgroud)

android kotlin

2
推荐指数
1
解决办法
2391
查看次数

将一个 ImageView 锚定到另一个 ImageView 的一角

两个图像视图相互重叠

如何将 ImageView 锚定到另一个 ImageView 的右下角,如上图所示(1 人和 2 铅笔)

我正在使用改造将我的源作为椭圆形加载到 ImageViews 中

我这样做:

   Glide.with(context)
        .asBitmap()
        .load(model)
        .fitCenter()
        .apply(RequestOptions.circleCropTransform())
        .into(object : BitmapImageViewTarget(this) {
            override fun setResource(resource: Bitmap?) {
                setImageDrawable(
                    resource?.run {
                        RoundedBitmapDrawableFactory.create(
                            resources,
                            if (borderSize > 0) {
                                createBitmapWithBorder(borderSize, borderColor)
                            } else {
                                this
                            }
                        ).apply {
                            isCircular = true
                        }
                    }
                )
            }
        })
Run Code Online (Sandbox Code Playgroud)

layout android imageview kotlin

-2
推荐指数
1
解决办法
881
查看次数

标签 统计

android ×3

kotlin ×3

imageview ×1

layout ×1