ConstraintLayout в Android Studio не совпадает с родительским - PullRequest
0 голосов
/ 24 мая 2018

Я пытаюсь использовать ConstraintLayout в Android Studio и создаю фрагмент таким образом, в частности я использую android: layout_height = "match_parent".

Layout of fragment

Вот мой код.

<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"
android:background="@android:color/holo_blue_light"
tools:context="com.saffru.colombo.soccerstats.match.PrePartitaFragment">

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="Prepartita"
    android:textColor="@android:color/black"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintEnd_toStartOf="@+id/txtdate"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/txtdate"
    app:layout_constraintTop_toTopOf="parent" />

<EditText
    android:id="@+id/txtdate"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginTop="10dp"
    android:focusable="false"
    android:hint="Tocca per inserire la data*"
    android:textSize="20sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView3" />


<ListView
    android:id="@+id/ListView01"
    android:layout_width="match_parent"
    android:layout_height="300sp"
    android:layout_marginEnd="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginStart="10dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/et_avversario" />

<EditText
    android:id="@+id/et_avversario"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="10dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginStart="10dp"
    android:ems="10"
    android:hint="Avversario"
    android:inputType="textPersonName|textCapSentences"
    app:layout_constraintEnd_toStartOf="@+id/ListView01"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/ListView01"
    app:layout_constraintTop_toBottomOf="@+id/et_luogo" />

<CheckBox
    android:id="@+id/checkBox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
    android:text="In casa"
    app:layout_constraintTop_toBottomOf="@+id/txtdate" />

<EditText
    android:id="@+id/et_luogo"
    android:layout_width="260dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp"
    android:ems="10"
    android:hint="Luogo"
    android:inputType="textPersonName|textCapSentences"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toEndOf="@+id/checkBox"
    app:layout_constraintTop_toBottomOf="@+id/txtdate" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/submit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16sp"
    android:layout_marginEnd="16sp"
    android:layout_marginRight="16sp"
    android:background="@color/colorAccent"
    android:src="@drawable/ic_check"
    android:textColor="#fff"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent" />

Но когда я запускаю свое приложение, я вижу, что макет не "match_parent".

enter image description here

, а активность слегка прокручивается.

Есть идеи для решения этой проблемы?Вот моя активность xml.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout      
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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".match.PartitaSpinnerActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_weight="1"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:title="@string/app_name">

        <Spinner
            android:id="@+id/spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

Ответы [ 2 ]

0 голосов
/ 29 января 2019

Существует тип ограничения, которое нарушает функцию прокрутки:

Удаление атрибутов ниже из другого представления.

app:layout_constraintBottom_toBottomOf="parent"

Happy Coding ..

0 голосов
/ 24 мая 2018

Попробуйте добавить:

android:fillViewport="true"

к вашему NestedScrollView

<android.support.v4.widget.NestedScrollView
    android:id="@+id/container"
    android:fillViewport="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Обычно контейнер Fragment не имеет значения NestedScrollView.Обычно используется FrameLayout.Если вы хотите, чтобы его можно было прокручивать, оберните его с помощью NestedScrollView.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...