我是新来的,正在尝试学习 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
子视图不能指定match_parent
为其所需的尺寸。使用match_constraint
(0dp) 并将左/右或上/下约束设置为"parent"
。
小部件尺寸约束
可以通过3种不同的方式设置
android:layout_width
和android:layout_height
属性来指定小部件的尺寸:
- 使用特定维度(文字值,例如
123dp
或Dimension
引用)- 使用
WRAP_CONTENT
,这将要求小部件计算自己的大小- 使用
0dp
,相当于“MATCH_CONSTRAINT
”图 7 - 尺寸约束
前两种布局的工作方式与其他布局类似。最后一个将以匹配设置的约束的方式调整小部件的大小(参见图 7,(a) 是 wrap_content,(b) 是 0dp)。如果设置了边距,它们将在计算中被考虑在内(图 7,(c)与 0dp)。
重要提示:
MATCH_PARENT
不支持包含在 a 中的小部件ConstraintLayout
,尽管可以通过MATCH_CONSTRAINT
将相应的左/右或上/下约束设置为来定义类似的行为"parent"
。
来源:https : //developer.android.com/reference/android/support/constraint/ConstraintLayout.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句