Подтвердить что ты не робот

Android XML отключает нижнюю половину макета

У меня проблема с моим XML-макетом, что-то, что я думал, не даст мне много проблем. У меня есть макет ниже в представлении прокрутки, но нижняя часть макета обрезается. Я не вижу ничего из второго списка списка. Оглядываясь по сторонам, я не вижу ничего плохого в самом xml, и я не вижу, что я делаю неправильно.

Я попытался предложить проблему, добавляя вес к каждому из разных элементов, но это еще не решило проблему.

Я также добавил основное действие, в котором размещен фрагмент, который может помочь решить проблему.

Фрагмент 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinatorLayout">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="vertical">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <android.support.design.widget.TextInputLayout
            android:id="@+id/text_input_layout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <EditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Recipe Title"/>
        </android.support.design.widget.TextInputLayout>

        <TextView
            android:id="@+id/ingredientsHeading"
            android:layout_below="@+id/text_input_layout"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:text="Ingredients"
            android:textStyle="bold|italic"
            android:layout_weight="1" />
        <ListView
            android:id="@+id/ingredientsList"
            android:layout_below="@+id/ingredientsHeading"
            android:layout_above="@+id/directionsHeading"
            android:layout_width="wrap_content"
            android:layout_height="195dp"
            android:layout_weight="1"></ListView>

        <Button style="@style/Button"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Add Ingredient"
            android:id="@+id/addIngredient"
            android:layout_below="@+id/ingredientsList"
            android:enabled="true"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/directionsHeading"
            android:layout_below="@+id/addIngredient"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:text="Directions"
            android:textStyle="bold|italic"
            android:layout_weight="1" />
        <ListView
            android:id="@+id/directionsList"
            android:layout_below="@+id/directionsHeading"
            android:layout_width="wrap_content"
            android:layout_height="195dp"
            android:layout_weight="1"></ListView>

        <Button style="@style/Button"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Add Direction"
            android:id="@+id/addDirection"
            android:layout_below="@+id/ingredientsList"
            android:enabled="true"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1" />

    </LinearLayout>

</ScrollView>


<android.support.design.widget.FloatingActionButton
    android:id="@+id/filterButton"
    app:backgroundTint="@color/floatingButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:clickable="true"
    android:src="@drawable/ic_filter"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_marginBottom="63dp"
    android:layout_marginRight="16dp" />


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

Основной XML

<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout2">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"/>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

    <FrameLayout
        android:id="@+id/container_body"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

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


<fragment
    android:id="@+id/fragment_navigation_drawer"
    android:name="com.example.rory.pocketchef.Fragments.FragmentDrawer"
    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:layout="@layout/fragment_navigation_drawer"
    tools:layout="@layout/fragment_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>
4b9b3361

Ответ 1

Я решил проблему. Когда показывался вид прокрутки, нижняя часть обрезалась нижней панелью действия на фактическом телефоне. Поэтому, чтобы решить эту проблему, я добавил прописью в нижней части прокрутки, чтобы подтолкнуть ее вверх над панелью действий.

Новый макет следующим образом

Обновлен рабочий 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinatorLayout">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="vertical"
    android:paddingBottom="?android:attr/actionBarSize"> <<<-------added this line
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <android.support.design.widget.TextInputLayout
            android:id="@+id/text_input_layout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <EditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Recipe Title"/>
        </android.support.design.widget.TextInputLayout>

        <TextView
            android:id="@+id/ingredientsHeading"
            android:layout_below="@+id/text_input_layout"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:text="Ingredients"
            android:textStyle="bold|italic"
            android:layout_weight="1" />
        <ListView
            android:id="@+id/ingredientsList"
            android:layout_below="@+id/ingredientsHeading"
            android:layout_above="@+id/directionsHeading"
            android:layout_width="wrap_content"
            android:layout_height="195dp"
            android:layout_weight="1"></ListView>

        <Button style="@style/Button"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Add Ingredient"
            android:id="@+id/addIngredient"
            android:layout_below="@+id/ingredientsList"
            android:enabled="true"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/directionsHeading"
            android:layout_below="@+id/addIngredient"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:text="Directions"
            android:textStyle="bold|italic"
            android:layout_weight="1" />
        <ListView
            android:id="@+id/directionsList"
            android:layout_below="@+id/directionsHeading"
            android:layout_width="wrap_content"
            android:layout_height="195dp"
            android:layout_weight="1"></ListView>

        <Button style="@style/Button"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Add Direction"
            android:id="@+id/addDirection"
            android:layout_below="@+id/ingredientsList"
            android:enabled="true"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_below="@+id/addDirection">

            <Button style="@style/Button"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:text="Add Direction"
                android:id="@+id/showOptionsDialog"
                android:enabled="true"
                android:layout_gravity="center_horizontal"
                android:layout_weight="1" />

            <Button style="@style/Button"
                android:layout_width="wrap_content"
                android:layout_height="0dp"
                android:text="Add Direction"
                android:id="@+id/saveRecipe"
                android:enabled="true"
                android:layout_gravity="center_horizontal"
                android:layout_toRightOf="@+id/showOptionsDialog"
                android:layout_weight="1" />


        </RelativeLayout>

    </LinearLayout>

</ScrollView>


<android.support.design.widget.FloatingActionButton
    android:id="@+id/filterButton"
    app:backgroundTint="@color/floatingButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:clickable="true"
    android:src="@drawable/ic_filter"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_marginBottom="63dp"
    android:layout_marginRight="16dp" />


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

Ответ 2

используйте weightSum для всех компонентов в вашем XML файле,

Это android:layout_weight. Вес можно использовать только в LinearLayout. Если ориентация linearlayout Вертикальная, используйте android:layout_height="0dp", и если ориентация горизонтальная, используйте android: layout_width = "0d p". Он будет работать отлично.

Из вашего вопроса - нижняя часть макета обрезается

Это связано с фиксированной высотой, заданной компонентами.

EDIT - добавлен xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp"
    tools:context="info.androidhive.materialtabs.fragments.OneFragment">

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fadingEdge="none"
        android:fillViewport="true"
        android:isScrollContainer="true"
        android:scrollbars="none">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:weightSum="10">

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1">

                <android.support.design.widget.TextInputLayout
                    android:id="@+id/text_input_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <EditText
                        android:id="@+id/editText"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="Recipe Title" />
                </android.support.design.widget.TextInputLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="3.5"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/ingredientsHeading"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="5dp"
                    android:text="Ingredients"
                    android:textStyle="bold|italic" />

                <ListView
                    android:id="@+id/ingredientsList"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="center">

                <Button
                    android:id="@+id/addIngredient"
                    style="@style/AppTheme"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:enabled="true"
                    android:text="Add Ingredient" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="3.5"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/directionsHeading"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="5dp"
                    android:text="Directions"
                    android:textStyle="bold|italic" />

                <ListView
                    android:id="@+id/directionsList"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:gravity="center">

                <Button
                    android:id="@+id/addDirection"
                    style="@style/AppBaseTheme"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:enabled="true"
                    android:text="Add Direction" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

Ответ 3

Добавьте эти строки в свой ScrollView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"

android:scrollbars="vertical">

Ответ 4

Вы помещаете weightsum из 1 и ваш scrollview равен 28. Вы должны положить что-то вроде этого <LinearLayout weightsum=15> (вам не нужно ставить 15), а затем то, что находится внутри вашего макета, который вы должны распространять ваши 15 сум. Например, <TextView layout_weight=1> означает, что ваш textview будет равен 1/15. Когда я использую вес, я также устанавливаю высоту или ширину, в зависимости от того, какой из них я хочу играть, до 0dp. Например, если я хочу играть по ширине <TextView width=0dp height=wrap_content weight=1>. Поэтому вы должны дать вес каждому ребенку вашего LinearLayout. Надеюсь, что это поможет.

Изменить: также ListView в ScrollView не является хорошей идеей, может произойти отсюда. Посмотреть этот пост: Как я могу поместить ListView в ScrollView без его свертывания?