Android XML削减了布局的下半部分 [英] Android XML cutting off bottom half of layout

查看:59
本文介绍了Android XML削减了布局的下半部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的XML布局有问题,我认为这不会给我带来很多问题.我在滚动视图下面有一个布局,但是该布局的底部已被切除,在第二个列表视图之后看不到任何内容.从四周看,我似乎看不到xml本身有什么问题,也看不到我做错了什么.

I have a problem with my XML layout, something that I thought wouldn't give me many problems. I have a layout below in a scroll view, but the bottom of the layout is being cut off, I can't see anything past the second list view. From looking around, I can't seem to see anything wrong with the xml itself and I can't see what I am doing wrong.

我已经尝试过解决这个问题的建议,那就是增加每个不同元素的权重,但这仍然不能解决问题.

I have tried the suggestion to the problem, that is adding a weight to each of the different elements but this still hasnt solved the problem.

我还添加了将片段放置在其中的主要活动,以防可能有助于解决问题

I have also added the main activity in which the fragment is placed incase that might help solve the problem

片段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>

推荐答案

我解决了这个问题.在显示滚动视图时,实际电话上的底部操作栏将底部切除.因此,为解决此问题,我在滚动视图的底部添加了填充,以便将其向上推回操作栏上方.

I solved the issue. As the scroll view was being displayed the bottom was being cut off by the bottom action bar on the actual phone. So to solve this I added padding to the bottom of the scrollview in order to push it back up above the action bar.

新布局如下

更新后的有效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>

这篇关于Android XML削减了布局的下半部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆