2017-07-02 107 views
0

我刚开始使用android studio,我插入了一个按钮和文本字段。在预览面板看起来不错,但是当我运行应用程序的布局是不同的。 这是XML代码:Android工作室在模拟器上的不同布局

<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:paddingBottom="16dp" 
android:paddingTop="16dp" 
android:paddingLeft="16dp" 
android:paddingRight="16dp" 

tools:context="com.example.alexander.myapplication.MainActivity"> 


<TextView 
    android:id="@+id/message" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" 
    tools:ignore="HardcodedText" /> 

<Button 
    android:id="@+id/button" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button" 
    tools:layout_editor_absoluteX="119dp" 
    tools:layout_editor_absoluteY="222dp" 
    tools:ignore="HardcodedText,MissingConstraints" 
    android:onClick="buttonClicked" 
    /> 

This is how it looks like 谢谢!

回答

0

看行:

tools:layout_editor_absoluteX="119dp" 
tools:layout_editor_absoluteY="222dp" 

什么,他们说的是,你放置在一个绝对位置,但只有在编辑器中预览按钮。 当应用程序实际运行时(注意参数名称中的“编辑器”前缀),该按钮没有真正的放置值。

您需要在编辑器中定义实际值。

退房Android开发者网站上的这个指南: Build a Responsive UI with ConstraintLayout

0

我只是通过设置布局RelativeLayout的解决了这个问题。

相关问题