Android-Bottom表不会扩展

时间:2016-03-22 14:40:45

标签: android android-support-library drawerlayout bottom-sheet

基本上,我使用支持库中的底部工作表视图。它在按下FAB后打开。

这是底部工作表视图文件:

<LinearLayout
android:id="@+id/bottomSheetView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/bottom_sheet_behavior"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="150dp"

>


<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="New"
    android:id="@+id/newLabel"
    android:layout_gravity="center_horizontal" />

<View
    android:layout_width="fill_parent"
    android:layout_height="2dp"
    android:layout_below="@+id/newLabel"
    android:background="#c0c0c0"/>

<Button
    android:id="@+id/newFileButton"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:text="File"
    android:layout_gravity="center_horizontal"
    />

<Button
    android:id="@+id/newFolderButton"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:text="Folder"
    android:layout_gravity="center_horizontal"
    />
</LinearLayout>

这是主要的活动布局:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinator"
>



<android.support.v4.widget.DrawerLayout
 android:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"

>

<!-- The first child in the layout is for the main Activity UI-->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    tools:context=".MainActivity"
    android:background="#ffffffff"
    >


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:id="@+id/cwdLabel" />

    <!--view that creates a dividing line between listview and textview -->  
    <View
        android:layout_width="fill_parent"
        android:layout_height="2dp"
        android:layout_below="@+id/cwdLabel"
        android:background="#c0c0c0"/>

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/fileList"
        android:layout_below="@+id/cwdLabel"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:borderWidth="0dp"
        app:backgroundTint="@color/colorAccent"
        app:elevation="6dp"
        android:clickable="true"
        app:fabSize="normal"
        app:pressedTranslationZ="12dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/ic_add_white_18dp"
        />




</RelativeLayout>

<!-- Side navigation drawer UI -->
<ListView
    android:id="@+id/navList"
    android:layout_width="275dp"
    android:layout_height="match_parent"
    android:layout_gravity="left|start"
    android:background="#ffeeeeee"
    />




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


<include layout="@layout/bottom_sheet_new"/>


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

问题是,按FAB时底板不会打开。 相反,它会在您将抽屉滑出后打开。另外,底部工作表是透明的,这不是我设定的。

我四处寻找答案,在阅读了其他一些问题之后,我认为这与抽屉布局的提升有关,但我真的不知道如何解决这个问题

2 个答案:

答案 0 :(得分:0)

我有同样的问题,我将com.android.support:appcompat更新到最后一个版本,现在它可以正常工作了!

现在我已经

  • &#39; com.android.support:程序兼容性-V7:23.4.0&#39;
  • &#39; com.android.support:设计:23.2.0&#39;

答案 1 :(得分:0)

试试这个, 在初始化视图后将其放入

  ViewCompat.postOnAnimation(coordinator, new Runnable() {
            @Override
            public void run() {
                ViewCompat.postInvalidateOnAnimation(coordinator);
            }
        });

希望有所帮助