Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将XML转换为Anko DSL_Android_Kotlin_Anko - Fatal编程技术网

Android 将XML转换为Anko DSL

Android 将XML转换为Anko DSL,android,kotlin,anko,Android,Kotlin,Anko,我想将我的XML布局转换为Anko DSL,但我在CardView方面遇到了问题 <?xml version="1.0" encoding="utf-8"?> <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height=

我想将我的XML布局转换为Anko DSL,但我在CardView方面遇到了问题

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/cardview_manga"
    android:layout_margin="5dp">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/manga_cover"
            android:background="@color/placeholder_background"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:contentDescription="@string/cover" />

        <TextView
            android:id="@+id/manga_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:padding="5dp"
            android:background="#3f000000"
            android:textColor="#ffffff"
            android:textSize="14sp" />

    </FrameLayout>

</android.support.v7.widget.CardView>



对于第一个和第三个问题,您应该使用backgroundColorResource, 背景色用于静态颜色,即

backgroundColor = Color.YELLOW
backgroundColorResource = R.color.placeholder_background

我不知道第二个问题,似乎是边距或填充问题

对于第一个和第三个问题,您应该使用背景色资源, 背景色用于静态颜色,即

backgroundColor = Color.YELLOW
backgroundColorResource = R.color.placeholder_background

我不知道第二个问题,似乎是边距或填充问题

如何使用?我的意思是我对你在这里使用伴星有点困惑。关于颜色,你需要得到一个颜色类的实例,而不是Int-ContextCompat.getColor(context,R.Color.your所需的颜色)顺便说一句,你可以编写
override-fun-createView(ui:AnkoContext)=使用(ui){relativeLayout{…}
,不使用
.view
,以及
textSize=dip(14)
如何使用它?我的意思是我对你在这里使用伴星有点困惑。关于颜色,您需要获得一个颜色类的实例,而不是Int-ContextCompat.getColor(context,R.Color.your_desired_Color)顺便说一句,您只需编写
override-fun-createView(ui:AnkoContext)=使用(ui){relativeLayout{…}
,而不使用
.view
,以及
textSize dip(14)