Show View as slide

Asked

Viewed 170 times

0

Hi, I would like to know how to make a View appear as slide on an android layout changing the size of your siblings, for example the information of a point in the Google Maps app that appears and changing the size of the map.

  • The information is hidden and the map occupies the whole screen A informação estar escondida e o mapa ocupa a tela toda

  • The information is displayed and the map size decreases A informação é mostrada e o tamanho do mapa diminui

  • Silas, I’ve had the same problem as you, but the only limitation of my solution is that I couldn’t make the map "fit". That is, it was reduced in size, but did not center (in the smaller area) on the same point that was centered (before expanding content). If you want I can include my solution as an answer.

  • Okay, I want to see your solution.

1 answer

1


I will assume that the content behind the slider is not part of the question. Only the slider implementation will be addressed.

In my solution, I made use of Android Sliding Up Panel, as an example application in the app Umano.

If using the Maven or the Gradle to resolve its dependencies, just include this library as a dependencies:

Example using the Gradle:

dependencies {
    repositories {
        mavenCentral()
    }
    compile 'com.sothree.slidinguppanel:library:+'
}

For the perfect operation, the library forces a structure into its layout.

  1. Include the com.sothree.slidinguppanel.SlidingUpPanelLayout as the root element of your layout (be Fragment or his Activity).
  2. The gravity (com.sothree.slidinguppanel.SlidingUpPanelLayout) root accurate be or top or bottom. This attribute indicates which direction your slider will appear.
  3. Make sure that the root has two children. The first child needs to be the main layout. The according to child is the layout for the sliding panel.
  4. The child that is the main layout needs to have the attributes of width and height as being match_parent. The sliding panel, the second child, needs to have the attribute width as match_parent and the attribute height or being match_parent or the height you want.
  5. By default, the entire panel acts as a "draggable" region, and will intercept by clicking and drag events. You can restrict the "draggable" area. Enough in your onCreate or onCreateView specify a View passing the method setDragView or the attribute dragView in your xml.

This is an example of layout using the library, taken from github repository:

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:panelHeight="68dp"
    sothree:shadowHeight="4dp">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:text="Main Content"
        android:textSize="16sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center|top"
        android:text="The Awesome Sliding Up Panel"
        android:textSize="16sp" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

A suggestion to have a smoother transition, that is, for the slider to be on top of the ActionBar, you will need to use an attribute in your theme:

<style name="AppTheme">
    <item name="android:windowActionBarOverlay">true</item>
</style>

The result will be something like this, of course there are other settings, which are available in the documentation on github1:

Exemplo do <code>Android Sliding Up Panel</code>

References:

  1. https://github.com/umano/AndroidSlidingUpPanel
  • thanks, it helped a lot.

  • old you me helped a lot, but application is getting problem rendering, the panel is not appearing right. Do you have any idea what this might be?

  • I think something to do with google maps

  • Silas, it is worth creating another question. Ai vc includes the layout code. To see how you included Google Maps. I can inline my code that uses Googlemaps as a gist and put here after, maybe to see the difference.

  • @Silasribeiro, take a look at this gist: https://gist.github.com/wakim/eb990978344f13e4cf89. Of course I have removed some parts because they are not directly connected to the Sliding Up Panel, if something is missing just let me know that I put.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.