Android 为什么我用作片段容器的FrameLayout不使用全屏宽度?

Android 为什么我用作片段容器的FrameLayout不使用全屏宽度?,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,由于某些原因,我的框架布局没有一直延伸到屏幕边缘 以下是我的活动布局: 那么问题是什么呢?当我在设计视图中查看片段布局时,它看起来很好 问题似乎只有在将片段添加到我的活动布局后才会出现,请参见上面的代码和布局。我该如何解决这个问题 编辑:我不明白为什么我得到了反对票。至少你可以留下一条评论来解释问题的症结所在。将FrameLayout宽度设置为与父项匹配如何! 编辑: 对于ConstraintLayout,将当前框架布局替换为: 并确保您有xmlns:app=http://schemas.a

由于某些原因,我的框架布局没有一直延伸到屏幕边缘

以下是我的活动布局:

那么问题是什么呢?当我在设计视图中查看片段布局时,它看起来很好

问题似乎只有在将片段添加到我的活动布局后才会出现,请参见上面的代码和布局。我该如何解决这个问题

编辑:我不明白为什么我得到了反对票。至少你可以留下一条评论来解释问题的症结所在。

将FrameLayout宽度设置为与父项匹配如何! 编辑: 对于ConstraintLayout,将当前框架布局替换为:


并确保您有xmlns:app=http://schemas.android.com/apk/res-auto 在您的xml根布局声明中。

您的活动布局看起来像什么?@dhiku问题中指定了我的活动布局:…为什么-1?这是一个合理的问题!Android studio不让我这么做。当我将其设置为匹配父对象时,它会将其更改为368Pi。如果FrameLayout位于ConstraintLayout内,则将前者的宽度设置为0,并将属性layout\u constraintLeft\u设置为RefTof,layout\u ConstraintTright\u设置为parent。我这样做了,现在屏幕是空白的我将此添加到我的框架布局:app:layout\u constraintLeft\u toLeftOf=@+id/父应用程序:layout\u constraintRight\u toRightOf=@+id/parents您的意思是将其添加到活动中的框架布局中吗?还是在片段的框架布局中?
<FrameLayout
    android:id="@+id/contactInfoFragmentContainer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="8dp">

</FrameLayout>
<!-- TODO: Update blank fragment layout -->

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="1"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="8dp">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="220dp"
        app:srcCompat="@android:drawable/btn_dialog"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="0dp" />

    <LinearLayout
        android:id="@+id/thumbnailsLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.05"
        android:orientation="horizontal">

        <HorizontalScrollView
            android:id="@+id/Thumbnails"
            android:layout_width="260dp"
            android:layout_height="97dp">

        </HorizontalScrollView>

        <Button
            android:id="@+id/addImage"
            android:layout_width="wrap_content"
            android:layout_height="96dp"
            android:layout_weight="1.06"
            android:text="Add image" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/shopNameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/nameTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Name" />

        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="textPersonName" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/phoneNumberLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Phone" />

        <Spinner
            android:id="@+id/spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <EditText
            android:id="@+id/phoneText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="number" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/addressLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

        <EditText
            android:id="@+id/addressText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="10"
            android:inputType="textPostalAddress" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"></LinearLayout>
</LinearLayout>
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_shop);

        // Check that the activity is using the layout version with
        // the fragment_container FrameLayout
        if (findViewById(R.id.contactInfoFragmentContainer) != null) {

            // However, if we're being restored from a previous state,
            // then we don't need to do anything and should return or else
            // we could end up with overlapping fragments.
            if (savedInstanceState != null) {
                return;
            }

            // Create a new Fragment to be placed in the activity layout
            ContactInfoFragment firstFragment = new ContactInfoFragment();

            // In case this activity was started with special instructions from an
            // Intent, pass the Intent's extras to the fragment as arguments
            firstFragment.setArguments(getIntent().getExtras());

            // Add the fragment to the 'fragment_container' FrameLayout
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.contactInfoFragmentContainer, firstFragment).commit();
        }
    }
<FrameLayout
    android:id="@+id/contactInfoFragmentContainer"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent">