gpt4 book ai didi

android-layout - Android - 如何将 SlidingUpPanelLayout 设置为屏幕高度的一半?

转载 作者:行者123 更新时间:2023-12-01 13:40:18 27 4
gpt4 key购买 nike

我正在使用 Umano 的 SlidingUpPanelLayout 来提供一个滑动面板,您可以从屏幕底部向上拖动它。您可以在此处找到文档:

https://github.com/umano/AndroidSlidingUpPanel

我想要它,以便面板在扩展时只填满屏幕的一半。文档说明了这一点:

  • The main layout should have the width and the height set to match_parent.
  • The sliding layout should have the width set to match_parent and the height set to either match_parent, wrap_content or the max desireable height. If you would like to define the height as the percetange of the screen, set it to match_parent and also define a layout_weight attribute for the sliding view.


这是我的包含滑动面板的 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>

我试过向 contact_details_frame 添加 layout_weight 属性,但它不起作用。事实上,当我尝试添加 layout_weight 属性时,Android Studio 不会自动完成(我猜是因为它需要在 LinearLayout 内才能使该属性在那里有效)。我已经尝试添加一个 LinearLayout,无论是单独的还是带有空的 View 来尝试占据屏幕的上半部分,但仍然没有。

有人能告诉我如何让 SlidingUpPanelLayout 只占据屏幕的一半吗?

最佳答案

我测试了很多方法,但没有一个有效,但是这是另一种方式。希望它有帮助:)

First: just change sothree:umanoPanelHeight value to 0dp that it'll hide bottom bar of SlidingUpPanelLayout


<com.sothree.slidinguppanel.SlidingUpPanelLayout
// your code
sothree:umanoPanelHeight="0dp">

Second: make a barlayout or button [Not in dragView]
(to open SlidingUpPanelLayout, instead of using the bar that SlidingUpPanelLayout shows itself)


<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btn_open_slide_panel"
android:text="open SlidingUpPanelLayout "/>

Third: in SetOnClickListener method of your view(that we made in second part)

  1. Call method setAnchorPoint() and pass 0.5f as argument
  2. Use ANCHORED as PanelState

slidingUpPanelLayout.setAnchorPoint(0.5f);
slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.ANCHORED);

希望能帮助到你 :)

关于android-layout - Android - 如何将 SlidingUpPanelLayout 设置为屏幕高度的一半?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40887760/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com