2017-06-28 3 views
0

Je reçois l'erreur qu'il manque des classes dans mon visualiseur XML. Donc, je ne peux pas voir ma mise en page dans l'aperçu, mais quand je lance l'application, je peux tout voir très bien.Les classes manquantes dans android studio 3.0 canary 4 ui aperçu

Les classes sont à l'intérieur d'un module dans mon projet studio Android et sont inclus comme ceci:

dependencies { 
    compile project(":styleguide") 
} 

et utilisé dans le code XML comme ceci:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginTop="64dp" 
    android:orientation="vertical"> 

     <com.company.packagename.buttons.SecondaryButtonLink 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent"/> 

</LinearLayout> 

Et le bouton ressemble à ceci: Le code derrière la classe de bouton est comme suit:

class SecondaryButtonLink @JvmOverloads constructor(
     context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 
) : LinearLayout(context, attrs, defStyleAttr) { 
    init { 
     initializeView(attrs) 
    } 

    private fun initializeView(attrs: AttributeSet?) { 
     val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater 
     inflater.inflate(R.layout.secondary_button_link, this) 

     if (attrs == null) return 
     checkForImage(attrs) 
     val typedArray = context.obtainStyledAttributes(attrs, R.styleable.StyleGuideButton) 
     if (typedArray.hasValue(R.styleable.StyleGuideButton_title)) { 
      setButtonTitle(typedArray) 
     } 

    } 

    private fun setButtonTitle(typedArray: TypedArray) { 
     for (i in 0..typedArray.indexCount - 1) { 
      val attr = typedArray.getIndex(i) 
      if (attr == R.styleable.StyleGuideButton_title) { 
       secondary_button_link_title_tv.text = typedArray.getString(attr) 
      } 
     } 
    } 

    private fun checkForImage(attrs: AttributeSet){ 
     val typedArray = context.obtainStyledAttributes(attrs, R.styleable.SecondaryButtonLink) 
     if (typedArray.hasValue(R.styleable.SecondaryButtonLink_rightimage)) { 
      setImage(typedArray) 
     } 
    } 

    private fun setImage(typedArray: TypedArray){ 
     for (i in 0..typedArray.indexCount - 1) { 
      val attr = typedArray.getIndex(i) 
      if (attr == R.styleable.SecondaryButtonLink_rightimage) { 
       secondary_button_link_title_tv.setCompoundDrawablesWithIntrinsicBounds(null, null, typedArray.getDrawable(attr),null) 
      } 
     } 
    } 
} 

Je n'arrive pas à préciser pourquoi il n'apparaît pas dans l'afficheur. Est-ce que quelqu'un a une idée pourquoi ne se présente pas?

Répondre

0

c'est un bug sur studio android Canary 4 il suffit d'utiliser Canary 1 jusqu'à ce qu'ils le réparent! :)