从底部到屏幕的一半视图

4
我希望有一个视图从底部出现,并使用动画填充半个屏幕。在这个视图中,我会有很多个 ImageButton。 我可以编写从底部到半屏幕的动画,但之后我的视图就会填满整个屏幕。
我想要的效果如下图所示: enter image description here 实际上,我得到的效果是这样的: enter image description here XML 代码:
<android.support.v4.widget.DrawerLayout
        android:id="@+id/screen_dashboard" style="@style/drawer"
        tools:openDrawer="start">
(...)
<TableLayout
            android:id="@+id/hidden_panel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:visibility="gone" >

            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">
                <ImageButton
                    android:id="@+id/button1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/app_name"
                    android:onClick="slideUpDown" />
                <ImageButton
                    android:id="@+id/button2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/app_name"
                    android:onClick="slideUpDown" />
            </TableRow>
        </TableLayout>
    </android.support.v4.widget.DrawerLayout>

Java代码:

public void slideUpDown(final View view) {

        if (!isPanelShown()) {
            // Show the panel
            Animation bottomUp = AnimationUtils.loadAnimation(this, R.animator.bottom_up);
            hiddenPanel.startAnimation(bottomUp);

            hiddenPanel.setVisibility(View.VISIBLE);
        }
        else {
            // Hide the Panel
            Animation bottomDown = AnimationUtils.loadAnimation(this, R.animator.bottom_down);

            hiddenPanel.startAnimation(bottomDown);
            hiddenPanel.setVisibility(View.GONE);
        }
    }

    private boolean isPanelShown() {
        return hiddenPanel.getVisibility() == View.VISIBLE;
    }

有没有人知道我该怎么做才能让我的视图仅填满半个屏幕?

2个回答

0
使用底部对话框片段。这将从底部动画显示,并默认从底部获取片段所需的大小。您无需编写额外的代码来实现动画效果。

BottomSheetDialogFragment


0

有两个快速解决方案可以满足您的需求:

1)BottomSheet。您可以使用app:behavior_peekHeight来配置此视图在展开状态下的高度。

2)MotionLayout。在这种情况下,您将能够配置状态之间的美丽过渡。此外,位于底部视图上方的视图可以动画转换到底部视图。但它仍处于alpha版本。因此,它可能包含错误,并且API在未来的发布中可能会发生重大变化。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接