Android 将XML转换为Anko DSL
我想将我的XML布局转换为Anko DSL,但我在CardView方面遇到了问题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 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)