Android工作室按钮没做任何事情真的很困惑

时间:2018-04-19 02:17:03

标签: android sdk

OnLongPress

<?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"
    android:background="@android:color/background_dark"
    tools:context="com.karanvir.stepcounter.MainActivity">

    <TextView
        android:id="@+id/value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        android:textColor="@android:color/holo_orange_light"
        android:textSize="50sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.461"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.433"
        tools:layout_constraintBottom_creator="1"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="65dp"
        android:background="@color/colorPrimary"
        app:srcCompat="@drawable/i"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintTop_creator="1"
        android:layout_marginTop="66dp"
        app:layout_constraintTop_toBottomOf="@+id/value"
        app:layout_constraintLeft_toLeftOf="parent"
        android:layout_marginLeft="65dp" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="48dp"
        android:background="@android:color/holo_orange_light"
        android:text="How it works"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="HardcodedText"
        tools:layout_constraintLeft_creator="1"
        tools:layout_constraintRight_creator="1"
        tools:layout_constraintTop_creator="1" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        tools:layout_constraintTop_creator="1"
        tools:layout_constraintLeft_creator="1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


</android.support.constraint.ConstraintLayout>

我已经发布了我项目的所有代码,其中包括xml和java代码。即时学习,只是玩一个有趣的项目。我从来没有遇到过这个错误,我认为它可能与“公共类MainActivity扩展AppCompatActivity实现SensorEventListener”有关,因为这是我第一次使用这样的东西。

2 个答案:

答案 0 :(得分:1)

您正在设置contentView 2次。

setContentView(R.layout.activity_main);

删除后一个。

答案 1 :(得分:1)

您使用setContentView(R.layout.activity_main)两次,删除第二个。

相关问题