androidandroid-studioandroid-layouttextviewnine-patch

9-Patch drawable showing incorrectly in Android Studio Layout Editor


This problem persists with "Android Studio Dolphin | 2021.3.1 Patch 1." Is this an issue of fidelity Android Studio vs. an android device/emulator?


I have a 9-patch drawable that displays incorrectly in the Android Studio Layout Editor but shows correctly on an emulator. Here is what the 9-patch looks like in the 9-patch editor of Android Studio. The 9-patch drawable is in the "drawable" folder.

enter image description here

Here is the XML for the layout:

<androidx.constraintlayout.widget.ConstraintLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:backgroundTint="@android:color/darker_gray">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/bubble"
        android:text="X"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Here is how it looks on and emulator running API 29:

enter image description here

which is what I expect. But here is what it looks like in the layout editor:

enter image description here

which is wrong.

I was going to submit this as a bug, but I thought that I may be missing something. Am I missing something? I have done a pretty extensive search but haven't come up with anything. The version of Android Studio I am using is Arctic Fox 2020.3.1 Patch 2 built on August 26, 2021. (This is also happening on Arctic Fox 2020.3.1 Patch 3 built on September 30, 2021.)

Update: I have taken another look at this. It is the 9-patch content patches that are not honored in the layout editor. Stretchable patches are honored.

Update: I found some issues in the bug tracker mentioning a problem with 9-patch backgrounds in ConstraintLayout. I am seeing a problem with ConstraintLayout, as documented above, but also with LinearLayout.


Solution

  • This issue has been corrected in Android Studio Flamingo | 2022.2.1 Patch 2 and maybe before.