Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android Studio 2.3中,Match_父项不在ImageView中工作_Android_Android Layout - Fatal编程技术网

在Android Studio 2.3中,Match_父项不在ImageView中工作

在Android Studio 2.3中,Match_父项不在ImageView中工作,android,android-layout,Android,Android Layout,我是新来的,正在尝试学习android编程,但我遇到了一个问题,无法解决这个问题,请帮助我解决这个问题。我使用的是Android Studio 2.3,问题是当我尝试在中使用“match_parent”值时 android:layout_width="match_parent" android:layout_height="match_parent" 它会自动转换为以下内容:- android:layout_width="0dp" android:layout_height="0dp" too

我是新来的,正在尝试学习android编程,但我遇到了一个问题,无法解决这个问题,请帮助我解决这个问题。我使用的是Android Studio 2.3,问题是当我尝试在中使用“match_parent”值时

android:layout_width="match_parent"
android:layout_height="match_parent"
它会自动转换为以下内容:-

android:layout_width="0dp"
android:layout_height="0dp"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="16dp" />
下面是我的完整代码,请帮助我

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.rj.happybirthday.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="36sp"
        android:textColor="@android:color/white"
        android:fontFamily="sans-serif-light"
        android:text="Happy Birthday Rj!"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="0dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:fontFamily="sans-serif-light"
        android:textColor="@android:color/white"
        android:textSize="36sp"
        android:text="From, Rj!"
        />

    <ImageView
        android:src="@drawable/party"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scaleType="centerCrop"
        tools:layout_editor_absoluteY="0dp"
        tools:layout_editor_absoluteX="16dp" />

</android.support.constraint.ConstraintLayout>

ConstraintLayout
子视图不能指定
匹配父视图作为其所需的尺寸。使用
匹配\u约束
(0dp),将左/右或上/下约束设置为
“父约束”

窗口小部件维度约束 小部件的尺寸可以通过3种不同的方式设置
android:layout_width
android:layout_height
属性来指定:

  • 使用特定维度(文字值,如
    123dp
    维度
    引用)
  • 使用
    WRAP_CONTENT
    ,这将要求小部件计算自己的大小
  • 使用
    0dp
    ,这相当于“
    MATCH\u CONSTRAINT

图7-尺寸约束

前两个布局的工作方式与其他布局类似。最后一个将调整小部件的大小,使其与设置的约束匹配(参见图7,(a)是wrap_内容,(b)是0dp)。如果设置了裕度,则在计算中会考虑这些裕度(图7,(c)为0dp)

重要
MATCH\u PARENT
不支持包含在
ConstraintLayout
中的小部件,尽管可以使用
MATCH\u CONSTRAINT
定义类似的行为,并将相应的左/右或上/下约束设置为
“PARENT”


来源:

不要使用约束布局开始学习,只使用线性布局和线性布局,一旦你掌握了它们,就只学习约束。这是一个新的自动布局删除它。@ SECTOR11,因为它是自动包含在每一个新的项目,我认为它适合于从Android开发开始。没错,这是为了更好地使用可视化布局编辑器,而不是直接使用XML编码。谢谢您的回复,现在我需要做什么?如何将其转换为相对布局,因为在as 2.3中默认为ConstraintLayout。感谢您的回复,,我尝试了MATCH_CONSTRAINT,但没有任何结果。请阅读全文,尤其是末尾标记为“重要”的部分。是的,我已阅读并感谢您所做的一切。。我已经删除了ConstraintLayout,现在正在使用相对布局。