【发布时间】:2017-08-03 17:49:24
【问题描述】:
我是 Android 新手,我只是在 android studio 上创建了我的第一个简单应用程序,但约束布局在真实手机或虚拟手机上无法正常工作。我打算在布局中心放置一个按钮,并在布局顶部放置一个编辑文本,但是当我运行时,它们都位于右上角布局的相同位置,所以我无法输入文本并按下按钮.
我尝试使用RelativeLayout 并且它有效,所以我猜问题来自ConstraintLayout。请帮我解决它!
我已经安装了“ConstraintsLayout For Android 1.0.1 或更低版本”和“Solver For ConstraintsLayout 1.0.1 或更低版本”。在 build.gradle 中添加了 compile 'com.android.support.constraint:constraint-layout:1.0.1'
我使用 Android Studio 2.3 版。
这是我的 xml 代码:
<?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="my.android.myfirstapp.MainActivity">
<Button
android:id="@+id/btn_jump"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jump Activity"
tools:layout_editor_absoluteX="128dp"
tools:layout_editor_absoluteY="269dp" />
<EditText
android:id="@+id/edt_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text=""
tools:layout_editor_absoluteX="85dp"
tools:layout_editor_absoluteY="62dp" />
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
在这里找到了答案。 stackoverflow.com/questions/44449275/…将styles.xml AppTheme改为Base.Theme
标签: java android android-layout android-studio mobile