AndroidStudio ConstrainLayout不起作用

时间:2019-05-07 18:31:34

标签: android android-constraintlayout android-studio-3.4

我是android studio的初学者,如果有人可以帮助我我是否缺少某些东西,我会为此感到头痛吗?。...约束布局有问题,问题是我放了一些元素(ImageView,Button不会匹配) )的布局并将其约束到父级,但是当我在模拟器中运行它时,它并没有显示。也不向我显示元素下的那些按钮连接BaseLine并删除该元素的约束。

“ screenShot”: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"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="343dp"
        android:layout_height="118dp"
        android:layout_marginTop="10dp"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_c`enter code here`onstraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:srcCompat="@tools:sample/backgrounds/scenic[7]" />

</android.support.constraint.ConstraintLayout>

2 个答案:

答案 0 :(得分:0)

  

当我在模拟器中运行它时,它只是不显示

问题在这里:

tools:srcCompat="@tools:sample/backgrounds/scenic[7]"

您需要了解tools是什么,因此建议您阅读一些文档。

请注意:

  

它是一个命名空间,它启用设计时功能(例如,在片段中显示哪种布局)或编译时行为(例如,将哪种收缩模式应用于XML资源)。生成应用时,生成工具会删除这些属性,因此不会影响APK的大小或运行时行为。

相反,您必须习惯在模拟器上显示它。

app:srcCompat="@drawable/your_drawable"

注意:记得添加:xmlns:app="http://schemas.android.com/apk/res-auto"

答案 1 :(得分:0)

我找到了解决方案。它在新的Android Studio 3.4中是不同的,您必须右键单击元素,然后选择“显示基线”。

相关问题