2017-03-05 86 views
-2

,当我遇到了以下问题,我沿YouTube上的一些Android的教程如下: (左设计师,右边的仿真器) enter image description hereGUI元素不能正常显示

我试着在谷歌搜索,但不能似乎找到了正确的联系。 有没有人有任何想法是怎么回事?我尝试删除并放置新的元素,但同样的问题不断发生。

[编辑] XML代码,我没有改变。这是用一个新项目创建的。 enter image description here 图片中的所有元素都被拖放。没有代码被改变。

<?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:visibility="visible" 
    tools:context="com.example.todor.myapplication.MainActivity"> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     tools:layout_editor_absoluteX="159dp" 
     tools:layout_editor_absoluteY="235dp" 
     tools:text="@string/loginbutton" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="132dp" 
     android:layout_height="31dp" 
     android:layout_marginBottom="42dp" 
     android:fontFamily="monospace" 
     android:textAlignment="center" 
     android:textColor="@color/colorAccent" 
     android:textColorHint="@android:color/holo_blue_bright" 
     android:textStyle="bold" 
     android:visibility="visible" 
     app:layout_constraintBottom_toTopOf="@+id/editText" 
     tools:text="@string/logintext" 
     tools:layout_editor_absoluteX="126dp" /> 

    <EditText 
     android:id="@+id/editText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="33dp" 
     android:width="300dp" 
     android:ems="10" 
     android:hint="@string/emailhint" 
     android:inputType="textEmailAddress" 
     app:layout_constraintBottom_toTopOf="@+id/editText2" 
     tools:layout_editor_absoluteX="42dp" /> 

    <EditText 
     android:id="@+id/editText2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="40dp" 
     android:width="300dp" 
     android:ems="10" 
     android:hint="@string/passowrdhint" 
     android:inputType="textPassword" 
     app:layout_constraintBottom_toTopOf="@+id/button" 
     tools:layout_editor_absoluteX="42dp" /> 
</android.support.constraint.ConstraintLay 

出>

+1

[Study layouts](https://developer.android.com/guide/topics/ui/declaring-layout.html) – nobalG

+0

@ilan Todorovic您的问题是什么?你的XML在哪里?你需要我们什么样的帮助? –

+0

@Charuක图像的左侧是我使用Designer放置的元素的顺序,右侧是模拟器中显示的内容。我没有弄乱代码。我不知道为什么会发生这种情况。 –

回答

1

下面为大家介绍一些技巧!

阅读关于Tools Attributes Reference

Android Studio中支持多种XML在工具命名空间使设计时属性设有(如在一个片段显示哪个布局)或编译时的行为(如应用于您的XML资源的缩小模式)。当您构建应用程序时,构建工具将删除这些属性,以便对您的APK大小或运行时行为有无效

您需要了解以下属性的区别!

tools:text="loginbutton" 
android:text="loginbutton" 

您的意见没有限制他们只设计时位置! 去设计,拖动角落,直到圆圈变为绿色,然后给constraint.Here是linkOneLinkTwoConstraintLayout

相关如果你搞砸了很大的时间,你可以用LinearLayout替代android.support.constraint.ConstraintLayout额外的指导,但这不是解决方案,而是另一种方式!