Androidss
Androidss

Reputation: 47

How to have the same SlidingUpPanel for all activities

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <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:umanoPanelHeight="68dp"
        sothree:umanoShadowHeight="4dp"
        sothree:umanoParallaxOffset="100dp"
        sothree:umanoDragView="@+id/dragView"
        sothree:umanoOverlay="true"
        sothree:umanoScrollableView="@+id/main">

        <!-- MAIN CONTENT -->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <android.support.v7.widget.Toolbar
                xmlns:sothree="http://schemas.android.com/apk/res-auto"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/main_toolbar"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                sothree:theme="@style/ActionBar"
                android:layout_width="match_parent"/>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scrollbars="vertical"
            android:layout_marginTop="?attr/actionBarSize"


            />
        </RelativeLayout>
        <!-- SLIDING LAYOUT -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff"
            android:orientation="vertical"
            android:clickable="true"
            android:focusable="false"
            android:id="@+id/dragView">
        <LinearLayout android:layout_width="match_parent"
            android:layout_height="68dp"
            android:orientation="horizontal"
            android:id="@+id/panel">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="68dp"
                android:orientation="vertical"
                android:layout_weight="0.8">

                <TextView
                    android:id="@+id/footer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:textSize="20sp"
                    android:gravity="center_vertical"
                    android:paddingLeft="10dp"/>
                <TextView
                    android:id="@+id/foooter"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:textSize="16sp"
                    android:gravity="center_vertical"
                    android:paddingLeft="10dp"/>

            </LinearLayout>
            <ImageButton
                android:layout_width="68dp"
                android:layout_height="68dp"
                android:src="@mipmap/playy"
                android:id="@+id/play"
                android:background="@null"
                />
            <ImageButton
                android:layout_width="68dp"
                android:layout_height="68dp"
                android:src="@mipmap/queue"
                android:id="@+id/queue"
                android:background="@null"
                />
        </LinearLayout>
            <FrameLayout
                android:id="@+id/ss"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:background="#ffffff"
                >

              <!--  <TextView
                    android:id="@+id/list_main"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="?attr/actionBarSize"
                    android:gravity="center"
                    android:text="Main Content"
                    android:clickable="true"
                    android:focusable="false"
                    android:focusableInTouchMode="true"
                    android:textSize="16sp" />-->

                    <LinearLayout android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical"
                        android:layout_below="@+id/panel">

                        <LinearLayout
                            android:id="@+id/songThumbnail"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:paddingTop="10dp"
                            android:paddingBottom="10dp"
                            android:gravity="center"
                            android:layout_weight="0.9"
                            android:layout_marginTop="?attr/actionBarSize"
                           >

                            <ImageView android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:id="@+id/album_art"
                                android:src="@mipmap/music"
                                />
                        </LinearLayout>


                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical"
                            android:layout_above="@+id/linearLayout"
                            android:layout_alignParentStart="true"
                            >

                            <SeekBar
                                android:id="@+id/songProgressBar"
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="20dp"
                                android:layout_marginLeft="20dp"
                                android:layout_marginBottom="20dp"

                                android:thumb="@mipmap/seek_handler"
                                                      android:progressDrawable="@mipmap/img_seekbar_bg"
                                android:paddingLeft="6dp"
                                android:paddingRight="6dp"/>

                            <!-- Timer Display -->
                            <LinearLayout
                                android:id="@+id/timerDisplay"
                                android:layout_above="@id/songProgressBar"
                                android:layout_width="fill_parent"
                                android:layout_height="wrap_content"
                                android:layout_marginRight="20dp"
                                android:layout_marginLeft="20dp"
                                android:layout_marginBottom="10dp">
                                <!-- Current Duration Label -->
                                <TextView
                                    android:id="@+id/songCurrentDurationLabel"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_weight="1"
                                    android:gravity="left"
                                    android:textColor="#eeeeee"
                                    android:textStyle="bold"/>
                                <!-- Total Duration Label -->
                                <TextView
                                    android:id="@+id/songTotalDurationLabel"
                                    android:layout_width="fill_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_weight="1"
                                    android:gravity="right"
                                    android:textColor="#04cbde"
                                    android:textStyle="bold"/>


                            </LinearLayout>
                        </LinearLayout>
                        <LinearLayout
                            android:layout_width="fill_parent"
                            android:layout_height="200dp"
                            android:orientation="horizontal"
                            android:gravity="center"
                            android:layout_weight="0.1"
                            android:id="@+id/linearLayout"
                            >


                            <!-- Previous Button -->
                            <ImageButton
                                android:id="@+id/bt_previous"
                                android:src="@mipmap/previous"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:background="@null"
                                android:layout_weight="2"
                                />

                            <!-- Backward Button -->

                            <!-- Play Button -->
                            <ImageButton
                                android:id="@+id/bt_play"
                                android:src="@mipmap/playy"
                                android:layout_width="100px"
                                android:layout_height="100px"
                                android:background="@null"
                                android:layout_weight="2"/>
                            <!-- Forward Button -->

                            <!-- Next Button -->
                            <ImageButton
                                android:id="@+id/bt_next"
                                android:src="@mipmap/next"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:background="@null"
                                android:layout_weight="2"
                                />


                        </LinearLayout>
                    </LinearLayout>

            </FrameLayout>



        </LinearLayout>
    </com.sothree.slidinguppanel.SlidingUpPanelLayout>






</RelativeLayout>

The above is my XML code for SlidingUpPanel, which is used in my Main Activity.It has two parts, main content (the normal screen) and the sliding content (which will come from bottom of the screen).Now the problem is this panel will only be displayed in the Main activity.I want to display the panel for all my activities.Guide me how to go about.

Please Help Thanks..!!

Upvotes: 0

Views: 645

Answers (2)

Umar Ata
Umar Ata

Reputation: 4268

well if you want same slidingmenu with same content in all your activities then simply create an Activity and code the logic of sliding menu there say its name to be BaseActivity then extend this BaseActivity in all other activites of your project instead of AppCompatActivity, so you will get it available in all activities.

Another approach would be a Fragment containing SlidingMenu as suggested in comments by @Veeresh , that is also a good option available for you

Answering your comment make a variable in your MainActivity like this

 public  SlidingUpPanelLayout ss; // this is important step , did you followed this in your mainactivity

its the class variable then inside onCreate method

ss=(SlidingUpPanelLayout) findViewById(R.id.sliding_layout);

then in other activities you can get it directly by ss

Upvotes: 0

Aneesh P V
Aneesh P V

Reputation: 1390

Create your sliding content in a separate layout and inflate it in your any activity

 LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);


        View inflatedLayout = inflater.inflate(R.layout.layout1, null, false);
        inflatedLayout.setLayoutParams(lp);

Upvotes: 0

Related Questions