【发布时间】:2016-11-30 11:56:52
【问题描述】:
我正在使用 Umano 的 SlidingUpPanelLayout 来提供一个可以从屏幕底部向上拖动的滑动面板。您可以在此处找到文档:
https://github.com/umano/AndroidSlidingUpPanel
我希望它在扩展时面板只占屏幕的一半。文档说明了这一点:
- 主布局的宽度和高度应设置为 match_parent。
- 滑动布局的宽度应设置为 match_parent,高度设置为 match_parent、wrap_content 或 max 理想的高度。如果您想将高度定义为 屏幕的百分比,将其设置为 match_parent 并定义一个 滑动视图的 layout_weight 属性。
这是我的包含滑动面板的 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.bleachedlizard.policeapp.mainactivity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.sothree.slidinguppanel.SlidingUpPanelLayout
android:id="@+id/sliding_up_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<include layout="@layout/main_content" />
<FrameLayout
android:id="@+id/contact_details_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
我尝试将 layout_weight 属性添加到 contact_details_frame 但它不起作用。事实上,当我尝试添加 layout_weight 属性时,Android Studio 不会自动完成(我猜是因为它需要在 LinearLayout 中才能使该属性在那里有效)。我尝试添加一个 LinearLayout,既可以单独添加,也可以使用空视图来尝试占据屏幕的上半部分,但仍然没有。
谁能告诉我如何让 SlidingUpPanelLayout 只占据屏幕的一半?
【问题讨论】:
标签: android-layout