TabbedActivity中的片段被裁剪

时间:2017-06-28 02:36:07

标签: android android-layout android-fragments

所以我将这个fragment_list.xml放在 TabbedActivity 中。它有 ListView FloatingActionButton 。但是我不知道为什么,片段有点裁剪,所以ListView不能向下滚动到底部,而FAB只显示一点点。

这是它的图片。它位于卷轴的底部:

Image

fragment_list.xml

<FrameLayout 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"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.garudamaya.dennydap.lookingood.BlankFragment">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
            <ProgressBar
                android:id="@+id/listProgress"
                android:layout_width="64dp"
                android:layout_height="64dp"
                android:layout_centerVertical="true"
                android:layout_centerHorizontal="true"/>
            <ListView
                android:id="@+id/listView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:divider="@null"
                android:dividerHeight="0dp">
            </ListView>
    </RelativeLayout>
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right|end"
        android:layout_margin="@dimen/fab_margin"
        android:background="@color/colorPrimaryDark"
        app:srcCompat="@drawable/ic_sort_by_alpha_white_24px"
        app:rippleColor="#FFF"/>
</FrameLayout>

fragment_tabbed.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.garudamaya.dennydap.lookingood.MainActivity$PlaceholderFragment">

    <TextView
        android:id="@+id/section_label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

activity_tabbed.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="com.garudamaya.dennydap.lookingood.MainActivity">

    <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:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay">

        </android.support.v7.widget.Toolbar>

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

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

    <android.support.v4.view.ViewPager
        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 :(得分:0)

答案是: - 解决不同的布局和使用总和以解决此问题

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="2">

    <ListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.6"
        android:divider="@null"
        android:dividerHeight="0dp"></ListView>


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.4">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_gravity="bottom|right"
            android:background="@color/colorPrimaryDark"
            app:rippleColor="#FFF"
            app:srcCompat="@drawable/ic_sort_by_alpha_white_24px" />
    </RelativeLayout>
</LinearLayout>

我跳这个布局是完美的并解决了这个问题

答案 1 :(得分:0)

试试这个,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="fill_parent"
    android:layout_height="fill_parent">


    <ProgressBar
        android:id="@+id/listProgress"
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:visibility="gone" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/mRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:dividerHeight="0dp" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom|right|end"
        android:layout_marginBottom="60dp"
        android:layout_marginRight="8dp"
        android:background="@color/colorPrimaryDark"
        app:rippleColor="#FFF"
        app:srcCompat="@drawable/ic_home_blue" />
</RelativeLayout>