我正在使用umano的slideuppanellayout来提供一个滑动面板,您可以从屏幕底部拖动。您可以在此处找到文档:
https://github.com/umano/androidslidinguppanel
我想要它,以便面板扩展时仅填充一半的屏幕。文档指出以下内容:
- 主布局应具有宽度和高度设置为匹配_PARENT。
- 滑动布局应具有宽度设置为match_parent,并且设置为match_parent,wrap_content或max 理想的高度。如果您想将高度定义为 屏幕的percetange,将其设置为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不会自动完成(我猜它是因为它需要在线性延迟内部以使该属性在此处有效)。我已经尝试添加一个单独的laylayout,既可以单独又有一个空视图来尝试占据屏幕的上半部,但仍然没有。
有人可以告诉我如何让Slidinguppanellayout仅占屏幕的一半?
我测试了很多方法,但是它们不起作用,,但是这是另一种方法。希望它有帮助:)
first :只需更改 sothree:umanopanelheight value to 0DP ,它将隐藏 Slidinguppanellayout
<com.sothree.slidinguppanel.SlidingUpPanelLayout
// your code
sothree:umanoPanelHeight="0dp">
second :制作 barlayout 或按钮 [不在dragView中]
(打开slidinguppanellayout,而不是使用slidinguppanellayout显示自身的栏)
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn_open_slide_panel"
android:text="open SlidingUpPanelLayout "/>
第三:在您的视图的setonClickListener方法中(我们在第二部分中制作)
- 呼叫方法 setanchorpoint() and Pass 0.5F 作为参数
- 使用锚定 a panelstate
slidingUpPanelLayout.setAnchorPoint(0.5f);
slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);
希望它有帮助:)