Pardeep Kumar
Pardeep Kumar

Reputation: 950

How to display a view on top of another view in same activity

I am have an activity in android application . It displays a view (lets say CurrentView)with a button in the centre of the screen . I am setting the content of the activity using : setContentView(R.layout.layout_xml_file); The layout xml file defines the button.

My requirement is that , when user clicks on the button , i need to show another view (lets say NewView)containing a listView on Current View. The NewView transition should happen like this : It should start from bottom of the screen and should take some proportion of the screen , say 3/4 or 1/2 . I mean the view's height should be configurable . This NewView should be in the same activity . I do not want to create another activity for displaying it. I don't understand which android widget is should use for holding the NewView

Thanks. Your help is appreciated ...

Upvotes: 1

Views: 4497

Answers (4)

Dharmendra Pratap
Dharmendra Pratap

Reputation: 527

Take a Relative Layout align to bottom and set its height what you want and inside Relative Layout Take Listview after that setVisibility gone. And when click button in activity setVisibility Visible.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">


    <Button
        android:text="Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="128dp"
        android:id="@+id/button" />

    <RelativeLayout
        android:id="@+id/rel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerHorizontal="true"
        android:background="#f0f0f0"
        android:layout_below="@+id/button"
        android:visibility="gone">

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:divider="#000"
            android:dividerHeight="1dp"/>
    </RelativeLayout>
</RelativeLayout>

Upvotes: 3

Zahidul Islam
Zahidul Islam

Reputation: 3190

I think you are looking something like this library -> https://github.com/umano/AndroidSlidingUpPanel

Upvotes: 0

BlueMist
BlueMist

Reputation: 226

  1. use LinearLayout - layout_weight attribute in layout.xml
  2. View.setVisibility(View.VISIBLE or View.GONE)

Upvotes: 2

dumb_terminal
dumb_terminal

Reputation: 1825

perhaps use FrameLayout for both views parent layout. Initially the list should be inivisble and button visible.

Upvotes: 0

Related Questions