Relativelayout "anchored" at the bottom of the screen

Asked

Viewed 250 times

0

Next I want to make this layout (id div_external) below is anchored at the bottom of the screen. But look at the next one it’s at 0dp height on purpose, I don’t want it to appear unless I click the button. Until then everything well works perfectly...

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:background="#FF8800"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="osval.com.searchpeople.teste_act"
    tools:showIn="@layout/app_bar_teste_act">
        <RelativeLayout
            android:id="@+id/div_externa"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#FF555555"
            android:orientation="horizontal"
            android:animateLayoutChanges="true"></RelativeLayout>
</RelativeLayout>
However, by clicking the button again to close (which would be in case back to 0dp), He picks up the anchorage at the top of the layout, so at the first click of the button he starts to appear from the bottom up , and at other times it comes from the top down. the code I’m using to make this layout height change is this :

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);

        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        RelativeLayout rl = (RelativeLayout) findViewById(R.id.div_externa);
                        LayoutTransition lrl = rl.getLayoutTransition();

                        switch (lock){
                            case "Fechado" :
                                lrl.enableTransitionType(LayoutTransition.CHANGING);
                                rl.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                                        RelativeLayout.LayoutParams.MATCH_PARENT));
                                lock = "Aberto";
                                break;
                            case "Aberto" :
                                rl.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 0));
                                lock = "Fechado";
                                break;
                            default:
                                break;
                        }
                    }
                });
            }
        });

all this is "inside" the Navigationdrawer Standard Layout created by android studio

1 answer

1


I believe you only need to set one layout_height other than match_parent and use this attribute:

android:layout_alignParentBottom="true"

To hide/unhook do not need to move height, only use these commands:

rl.setVisibility(View.INVISIBLE); // Oculta
rl.setVisibility(View.VISIBLE); // Exibe
  • then ... I have already set the attribute android:layout_alignParentBottom="true" however when clicking the button it simply ignores and goes up

  • It may be because you are moving in height (especially because you are setting for match_parent, which occupies all available space within the parent). Try changing to the code I suggested.

  • but the idea is to make it look like the menu of UBER you know ? that goes from bottom to top and when closing it goes from top to bottom

  • I also don’t understand why you’re using a runnable.

  • I have removed the runnable , is why I was using the button to test a server response and needed it there hehe,

  • and using setVisibility the layout simply appears or simply disappears by clicking the button

  • I kind of want the Snackbar effect, which comes by default when creating a Navigationdrawer Activity, only without the close timer alone

  • The Uber menu to use a shared element transition effect where the menu is clicked on a second Activity when clicking the first Activity button and the elements that are "equal" between the activities make a transition animation that gives the impression of just moving in the same Activity. It is not difficult to implement: https://developer.android.com/training/material/animations.html?hl=pt-br#Transitions

  • OK Márcio, I will read what you sent there and soon I send an answer if I could or not , thank you for the attention

  • Good Marcio, it was a little more time consuming than I imagined , but in fact it is quite simple , I used only an Immature Object worked perfectly , but with this I showed me doing another effect that was much more interesting in the app , Thanks anyway !!!!

  • Ball show!!!

Show 6 more comments

Browser other questions tagged

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