Pet*_*ter 2 android android-layout android-studio
我正在关注youtube中的一些教程,并且学习了如何使用来添加背景色android:background = "#006699"。但是,我意识到当我使用此代码时,仿真器屏幕的只有一部分会变色。看起来像这样

这是我的content_main.xml代码
<?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:id="@+id/constraintLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background = "#006699"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:layout_editor_absoluteY="137dp"
tools:showIn="@layout/activity_main">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="160dp"
android:layout_marginStart="160dp"
android:layout_marginTop="244dp"
android:text="TextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
仅在文本框被着色的位置。为什么会这样?提前致谢!
您的版式已wrap_content为android:layout_width和设置了值android:layout_height。您应该改用match_parent值。
wrap_content 根据子项的大小自行布局。
match_parent另一方面使其完全扩展到其父级的最大可用大小。在这种情况下,当它是根布局时,要扩展到整个可用空间。
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |