Home>

Press the button to select player and vibrate according to the value sent from MilkCocoa

Error message

There was no error on the source
An error occurred in activity_main.xml

  

Failed to load AppCompat ActionBar with unknown error.
  The three buttons that should have been displayed were not displayed

Error message



When designed and run

Applicable source code

Enter only the text that describes the button

<? xml version = "1.0" encoding = "utf-8"?>
<android.support.constraint.ConstraintLayout xmlns: android = "http://schemas.android.com/apk/res/android"
    xmlns: app = "http://schemas.android.com/apk/res-auto"
    xmlns: tools = "http://schemas.android.com/tools"
    android: layout_width = "match_parent"
    android: layout_height = "match_parent"
    tools: context = ". MainActivity">
    <LinearLayout
        android: layout_width = "0dp"
        android: layout_height = "0dp"
        android: orientation = "vertical"
        app: layout_constraintBottom_toBottomOf = "parent"
        app: layout_constraintEnd_toEndOf = "parent"
        app: layout_constraintStart_toStartOf = "parent"
        app: layout_constraintTop_toTopOf = "parent">
        <Button
            android: id = "@ + id/button1"
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: text = "Player1" />
        <Button
            android: id = "@ + id/button2"
            android: layout_width = "match_parent"
            android: layout_height = "wrap_content"
            android: text = "Player2" />
        <Button
            android: id = "@ + id/penalty_button"
            android: layout_width = "match_parent"
            android: layout_height = "373dp"
            android: text = "Touch !!!!!" />
    </LinearLayout>
</android.support.constraint.ConstraintLayout>
Supplemental information (FW/tool version etc.)

I use AndroidStudio 3.14

  • Answer # 1

    Current Android Studio uses ConstraintLayout as the root view standard, but the component placed inside this is given aconstraint(direct translation of Constraint) to determine the position is needed. A component whose position is not fixed will appear in the editor, but it will not be visible on the terminal where it was executed.

    In the case of this question, the position of the LinerLayout that is placed as a child view of the ConstraintLayout is not fixed, so it will not be reflected at runtime, and the child view of the LinerLayout will disappear accordingly.

    With LinerLayout highlighted in the Component Tree, edit the diagram just below Attributes in the upper right to make it look like this: This gives the constraint that the four sides touch the parent view.

    If you edit XML directly,

    <LinearLayout
            android: layout_width = "0dp"
            android: layout_height = "0dp"
            android: orientation = "vertical"
            app: layout_constraintBottom_toBottomOf = "parent"
            app: layout_constraintEnd_toEndOf = "parent"
            app: layout_constraintStart_toStartOf = "parent"
            app: layout_constraintTop_toTopOf = "parent">
    As in

    , set android: layout_width and android: layout_height to 0dp, and add the following four attributes below app: layout_constraintBottom_toBottomOf.