Java Android Studio:在RelativeLayout的编辑模式下,按钮不显示

Java Android Studio:在RelativeLayout的编辑模式下,按钮不显示,java,android,xml,android-studio,Java,Android,Xml,Android Studio,我已经尝试过为这个问题寻找许多解决方案,但没有一个对我有效。以下是我的主要活动的.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:/

我已经尝试过为这个问题寻找许多解决方案,但没有一个对我有效。以下是我的主要活动的.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>
我不知道我的代码中是否缺少某些东西,或者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_down=“@id/rl_全天”

如果要确定子级和父级之间的相对位置,应使用

android:layout\u alignParentStart=“true”


没有必要同时使用alignPargentStart和alignParentLeft

尝试使用
LinearLayout
而不是
RelativeLayout
,因为
LinearLayout
可以让您更多地了解编码,并有助于创建更动态的内容

以下是
LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    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" />

</LinearLayout>

如果预览在IDE中不起作用,请更改渐变依赖项,如下所示

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleDependency
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'junit:junit:4.12'
}

解决方案是将支持库版本降级为
alpha1

删除
app:layout\u constraintBottom\u toBottomOf=“parent”app:layout\u constraintLeft\u toLeftOf=“parent”app:layou\u constraintRight\u toRightOf=“parent”app:layout\u constraintotop\u tototopof=“parent”
我刚刚应用了更改。什么也没发生。你的IDE好像有问题……你试过重新启动Android StudioYeah,还是没什么。当我删除alignParentLeft时,它警告我不要这样做,并告诉我重新添加它以支持旧版本的Android。此外,我删除了ConstraintLayout代码,但没有任何效果。很详细。当我说ConstraintLayout代码时,我的意思是像app:layout\u constraintBottom\u toBottomOf=“parent”和其他三个。删除ConstraintLayout代码时,是否向textview添加了其他属性?例如android:layout\u alignParentEnd=“true”,可能您的按钮被textview覆盖。顺便说一下,您可以尝试文件->使缓存无效/重新启动。。。重新启动Android Studioat build.gradle(项目)文件
android:padding="25dp"
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleDependency
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'junit:junit:4.12'
}