无法在Android Studio中呈现MvRx XML布局文件

时间:2018-10-09 12:09:45

标签: android kotlin android-studio-3.0 epoxy

在AirBnB的example repo中,新框架MvRx xml布局文件未在android studio编辑器中呈现,如以下屏幕截图所示。我也无法在Android Studio中为自己的项目渲染视图

enter image description here

full_screen_message.xml

<?xml version="1.0" encoding="utf-8"?>
<merge
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:parentTag="android.widget.FrameLayout"
    >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center"
        android:gravity="center_horizontal">
        <ImageView
            android:id="@+id/icon"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:scaleType="centerCrop"
            android:contentDescription="@string/asd" />

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/asdasdasdad"/>

    </LinearLayout>
</merge>

FullScreenMessageView.kt:

package com.airbnb.mvrx.todomvrx.views

import android.content.Context
import android.support.annotation.DrawableRes
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import com.airbnb.epoxy.ModelProp
import com.airbnb.epoxy.ModelView
import com.airbnb.epoxy.TextProp
import com.airbnb.mvrx.todomvrx.todoapp.R

@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_MATCH_HEIGHT)
class FullScreenMessageView @JvmOverloads constructor(
        context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    private val iconView by lazy { findViewById<ImageView>(R.id.icon) }
    private val titleView by lazy { findViewById<TextView>(R.id.title) }

    init {
        inflate(context, R.layout.full_screen_message, this)
    }

    @ModelProp
    fun setIconRes(@DrawableRes drawableRes: Int) {
        iconView.setImageResource(drawableRes)
    }

    @TextProp
    fun setTitle(title: CharSequence) {
        titleView.text = title
    }
}

0 个答案:

没有答案