RelativeLayout "anchored" at bottom of screen

0

Next I want to make this layout (from outer div id) below anchor at the bottom of the screen. But notice the following he is 0dp of height purposely, I do not want it to appear unless I click the button. So then everything works fine ...

<?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, when you click the button again to close (which would in this case return to 0dp), he takes the anchorage at the top of the layout, so in the first click of the button it starts to appear from the bottom up, and at the other times it comes from top to bottom. 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 Default Layout created by android studio

    
asked by anonymous 14.07.2017 / 14:50

1 answer

1

I think you just need to set%% of% to layout_height and use this attribute:

android:layout_alignParentBottom="true"

To hide / unhide, you do not have to touch the height, just use these commands:

rl.setVisibility(View.INVISIBLE); // Oculta
rl.setVisibility(View.VISIBLE); // Exibe
    
14.07.2017 / 15:19