【问题标题】:How to make a Sliding Up Panel in Android?如何在 Android 中制作上滑面板?
【发布时间】:2019-12-04 18:15:08
【问题描述】:

我想在我的项目中添加一个上滑面板。但我不知道该怎么做。我想在以下布局中添加滑动面板:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/mainFragment"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F7FEFF"
    tools:context="app.meetgreet.meetgreet.MainActivity">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="app.meetgreet.meetgreet.MapsActivity" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:textColor="@color/colorAccent"
        android:textSize="30sp"
        android:visibility="invisible"
        app:layout_constraintBottom_toBottomOf="@+id/scrollView2"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/scrollView2"
        app:layout_constraintVertical_bias="0.36" />

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <LinearLayout
            android:id="@+id/linearLayoutMain"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:orientation="vertical" />
    </ScrollView>

    <ImageButton
        android:id="@+id/imageButton"
        style="@style/Widget.AppCompat.ImageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/transparent"
        android:contentDescription="@string/settings"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_icons8_benutzereinstellungen_64" />

</androidx.constraintlayout.widget.ConstraintLayout>

我已经实现了这个库:

 implementation 'com.sothree.slidinguppanel:library:3.4.0'

以下部分应该是mainLayout。所以它不是滑动面板的一部分。它提供了一个谷歌地图。

<fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="app.meetgreet.meetgreet.MapsActivity" />

除 ImageButton 之外的所有其他视图都应该是滑动面板的一部分。 ImageButton 应该在屏幕的顶部,如果面板到达顶部,它就会消失。我希望有人可以帮助我实现它! 我已经尝试按照 GitHub 上的说明进行操作: https://github.com/umano/AndroidSlidingUpPanel 无论如何,它不起作用。

谢谢!

【问题讨论】:

    标签: java android xml layout slidingpanelayout


    【解决方案1】:

    这是一个简单的例子 activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        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:id="@+id/slide_up"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        tools:context=".MainActivity"
        app:umanoPanelHeight="70dp"
        app:umanoShadowHeight="5dp">
    
    <!-- main content -->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="app.meetgreet.meetgreet.MapsActivity" />
    
        </RelativeLayout>
    
    <!-- sliding part -->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
    
            <include layout="@layout/example" />
    
        </RelativeLayout>
    
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>
    

    example.xml

    <RelativeLayout
    
       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" >
    
    
        <!-- this is the header-->
        <LinearLayout
            android:id="@+id/header_layout"
            android:layout_width="match_parent"
            android:layout_height="70dp"
            android:orientation="horizontal"
            android:clickable="true"
            android:background="@color/backgroundColor"
            android:gravity="center">
    
    <!-- some views here -->
    
    </LinearLayout>
    
    
        <!-- this is the content -->
    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true">
    
    <!-- some views -->
    
    </RelativeLayout>
    
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 2022-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多