我的预览中的一切看起来都很好,但是当我在模拟器中打开应用程序时,布局与父级的长度或宽度不匹配。一切都在它应该在布局内的位置,它不会在整个屏幕上伸展。这发生在应用程序的每个布局中(我使用片段)。为了解释更好的继承人pix:
**我拥有什么
这是XML。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="@drawable/hlineand"/>
<TextView
android:id="@+id/userTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="User"
android:textAlignment="center"
android:textAppearance="@android:style/TextAppearance.Material.Small"
android:textColor="@android:color/darker_gray"
android:textSize="30dp"/>
<TextView
android:id="@+id/updateTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:text="----"
android:textAlignment="center"/>
<EditText
android:id="@+id/emailEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:ems="10"
android:hint="e-mail"
android:inputType="textEmailAddress"
android:layout_below="@+id/userTextView"
android:layout_centerHorizontal="true"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/emailEditText"
android:layout_below="@+id/emailEditText"
android:layout_marginTop="24dp"
android:ems="10"
android:hint="password"
android:inputType="textPassword"/>
<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/passwordEditText"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Login"/>
</RelativeLayout>
这是我的内容main.xml。就像第一个提到的评论者一样,它就在那里。当我输入匹配父母&amp;匹配父,但没有调整大小宽度344px&amp;身高590px。我可以把它作为匹配父母的任何方式吗?
<?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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.a2.reach.MainActivity"
tools:showIn="@layout/app_bar_main">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="344dp"
android:layout_height="495dp"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
答案 0 :(得分:2)
通过将宽度高度更改为0dp而不是匹配parent&amp;来修复内容主XML。在框架布局的底部添加4个约束。谢谢你们,感谢@ Du.fantasy指导我这么快的正确方向
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="0dp"
android:layout_height="0dp"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
答案 1 :(得分:1)
将FrameLayout
更改为与固定宽度和高度匹配的匹配_parent
<?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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.a2.reach.MainActivity"
tools:showIn="@layout/app_bar_main">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteY="8dp"
tools:layout_editor_absoluteX="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
答案 2 :(得分:0)
据我所知,在您的第一个XML中,您正在为for i in test_list:
if i == '0':
fig[0] = off
fig[1] = off
elif i == '1':
fig[0] = off
fig[1] = on
new_list.append(fig[:]) # <== Copy the array fig and append that value
提供相对布局。如果您希望它应该工作,那么您应该使用线性布局并使用该布局的方向。
尝试在内容XML中使用这样的内容:
orientation="vertcial"
答案 3 :(得分:-1)
在我的变体中更改大小父布局 - 修复了我的问题
<块引用> <FrameLayout
android:id="@+id/map_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>