2017-08-05 128 views
-3

我是Android开发新手,我试图用一个按钮创建应用程序。Android - 按钮不会出现

我使用Intellij设计工具来使我的布局和一切似乎确定,但是当我尝试运行该应用程序时,我的屏幕上没有按钮。

这里是我的活动文件:

<?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="com.test.button test.MainActivity" tools:layout_editor_absoluteY="81dp" 
     tools:layout_editor_absoluteX="0dp"> 

    <Button 
      android:text="Hello" 
      android:id="@+id/button" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      app:layout_constraintRight_toRightOf="parent" app:layout_constraintLeft_toLeftOf="parent" 
      app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintTop_toTopOf="parent" 
      tools:layout_constraintTop_creator="1" tools:layout_constraintRight_creator="1" 
      tools:layout_constraintBottom_creator="1" tools:layout_constraintLeft_creator="1"/> 
</android.support.constraint.ConstraintLayout> 

编辑: 更改的Android:layout_width = “0dp” 到Android:layout_width = “WRAP_CONTENT” 不会改变任何东西。

+0

的android:layout_width = “0dp”=>的android:layout_width = “WRAP_CONTENT” –

+0

你的android:layout_width = “0dp” – Mike

+0

还没与layout_width = “WRAP_CONTENT” 仍在工作 – Itega

回答

0

你给你的按钮的宽度为0。所以这对你不可见。给予宽度。 使用下面的Button代码;

<Button 
     android:id="@+id/join_now" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="15dp" 
     android:text="Join Now"/> 
+0

没有工作 – Itega

+0

删除这两条线:工具:layout_editor_absoluteY =“81dp” tools:layout_editor_absoluteX =“0dp” –

+0

它没有工作 – Itega

0

这是因为您使用ConstraintLayout,这将如果没有约束,给所有的按钮(0,0)复位。 尝试使用RelativeLayout或设置约束。