Android Studio模拟器中的项目位置错误 [英] Items are in wrong place in Android Studio emulator

查看:430
本文介绍了Android Studio模拟器中的项目位置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android studio的新手,这是我的第一款应用。
它工作正常但是模拟器出现问题,它在错误的位置显示按钮。

I'm new to android studio and this is my first app. It works correctly but having an issue with the emulator, it shows the button in the wrong place.

<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.example.dell_pc.myapplication.MainActivity">

    <EditText
        android:id="@+id/txtyear"
        android:layout_width="193dp"
        android:layout_height="60dp"
        android:ems="10"
        android:hint="Enter year of birth"
        android:inputType="number"
        tools:layout_editor_absoluteY="129dp"
        tools:layout_editor_absoluteX="96dp" />

    <Button
        android:id="@+id/butage"
        android:layout_width="115dp"
        android:layout_height="41dp"
        android:onClick="BuGetAge"
        android:text="Show Age"
        tools:layout_editor_absoluteY="277dp"
        tools:layout_editor_absoluteX="135dp" />

</android.support.constraint.ConstraintLayout>

如何让它出现在正确的位置?

How can I make it to appear in the right place?

推荐答案

您是否绝对需要使用约束布局?如果没有,你可以使用相对布局,并使用layout_centerHorizo​​ntal和layout_centerVertical,如下所示:

Do you absolutely need to use constraint layout? If not, you can use a relative layout, and use layout_centerHorizontal and layout_centerVertical like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">

    <EditText
        android:id="@+id/edittext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="blah blah"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="press"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/edittext"
        />

</RelativeLayout>

这篇关于Android Studio模拟器中的项目位置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆