java - Android Studio:在RelativeLayout中的编辑模式期间未显示按钮
问题描述
我已经尝试为这个问题寻找许多解决方案,但没有一个对我有用。这是我的主要活动的 .xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:text="9" />
</RelativeLayout>
这是我的Java代码:
package com.example.jacob.calculator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
我不知道我的代码中是否缺少某些内容,或者 android studio 是否有问题。任何帮助将不胜感激!
解决方案
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
这些属性用于 ConstraintLayout 而不是 RelativeLayout,而在 relativelayout 中如果要确定小部件之间的相对位置,则应使用
android:layout_below="@id/rl_all_day"
如果你想确定孩子和父母之间的相对位置,你应该使用
android:layout_alignParentStart="true"
不需要同时使用 alignPargentStart 和 alignParentLeft
推荐阅读
- error-handling - 如何使用此错误打印回溯而不惊慌?
- python - 如何在 tkinter sqlite 中使用占位符
- python - Pandas,Plotly 对秒进行分组而不重新采样
- c++ - CMake cpprestsdk
- java - 无论如何,是否可以使用 Java 代码从“PUBmed”文章中获取完整摘要
- javascript - JavaScript如何用另一个数组的每个元素替换数组的第一个元素
- amazon-web-services - 无法在 AWS 上设置 HashiCorp Vault
- node.js - Office 365 POP 提取邮件出现间歇性错误登录失败:未知用户名或密码错误
- ruby - 如何使用 unixODBC 从 DB2 V11.5 Linux 上的表 SYSIBM.SQLCOLUMNS 获取 column_def 值 - Ruby
- android - 单击登录按钮时应用程序崩溃(简单登录注册测试)