0

Hi i want to show custom pop up layout bottom of action bar. But i tried to position a view to another view.

What i wanted is : enter image description here

And i am actually getting is :

enter image description here

What i Tried to acieve this.

// Inflate layout

View filterLayout = getLayoutInflater().inflate(R.layout.tooltip_layout, null);
        filterPopup = new PopupWindow(this);
       /* filterPopup.setWidth(ListPopupWindow.MATCH_PARENT);
        filterPopup.setHeight(ListPopupWindow.WRAP_CONTENT);*/
        filterPopup.setOutsideTouchable(true);
        filterPopup.setContentView(filterLayout);
        filterPopup.setBackgroundDrawable(new BitmapDrawable());
        filterPopup.setFocusable(true);

// Show layout bottom of action bar

int[] location = new int[2];
                                                mActivityMainBinding.appBarMain.contentMain.mainContentLayout.getLocationOnScreen(location);
                                                Point point = new Point();
                                                point.x = location[0];
                                                point.y = location[1];

                                                filterPopup.showAtLocation(mActivityMainBinding.appBarMain.toolbar, Gravity.LEFT | Gravity.TOP, point.x, point.y);

// This is my tool tip layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    card_view:cardBackgroundColor="#fffff">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/color_white"
            android:orientation="vertical"
            android:padding="10dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/futura_medium"
                android:text="Have you selected the right location ?"
                android:textColor="@color/colorSection"
                android:textSize="@dimen/text_sizes_medium" />

            <View
                android:layout_width="match_parent"
                android:layout_height="10dp" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fontFamily="@font/futura_medium"
                android:lineSpacingExtra="4dp"
                android:text="Your selected location seems to be little far off from your device location"
                android:textColor="@color/colorTextPrimery"
                android:textSize="@dimen/text_sizes_medium" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="10dp"
                android:gravity="center"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/text_no_thanks"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:fontFamily="@font/futura_medium"
                    android:gravity="center"
                    android:text="NO THANKS"
                    android:textColor="@color/colorTextPrimery"
                    android:textSize="@dimen/text_sizes_smaller" />

                <View
                    android:layout_width="20dp"
                    android:layout_height="match_parent" />

                <TextView
                    android:id="@+id/text_change_location"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="end"
                    android:background="@drawable/selector_ligt_to_dark_no_radius"
                    android:fontFamily="@font/futura_medium"
                    android:gravity="center"
                    android:padding="6dp"
                    android:text="CHANGE LOCATION"
                    android:textColor="@color/color_white"
                    android:textSize="@dimen/text_sizes_smaller" />
            </LinearLayout>
        </LinearLayout>
    </android.support.v7.widget.CardView>

    <ImageView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_marginLeft="60dp"
        android:background="@android:color/transparent"
        android:src="@drawable/arrow_white" />

</FrameLayout>

Can anyone please guide me what can i do for achieving this ? I want to show the card view layout to align with action bar bottom alignment.

Deepak Rathore
  • 617
  • 8
  • 25
  • https://stackoverflow.com/questions/44917557/how-to-implement-a-small-popup-with-some-images-on-a-button-click/44917610#44917610 – AskNilesh Sep 19 '18 at 05:55
  • Hello @NileshRathod Thanks for answer. but the link you shared shows tooltip on other layout, but in my case i want card view alignment with alignment of action bar. Hope you understand. – Deepak Rathore Sep 19 '18 at 06:05

1 Answers1

0

complete guide :)

layout_popup.xml

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="130dp"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/expand"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:gravity="center"
                android:paddingLeft="10dp"
                android:text="@string/company"
                android:textAllCaps="true"
                android:textColor="#000000" />

            <ImageButton
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:background="#00000000"
                android:padding="7dp"
                android:scaleType="fitCenter"
                android:src="@drawable/arr" />

        </LinearLayout>

        <net.cachapa.expandablelayout.ExpandableLayout
            android:id="@+id/expandable_recycler_local"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"

            app:el_expanded="false">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rec_company_list"
                android:layout_width="130dp"
                android:layout_height="wrap_content"
                android:background="@drawable/round_shape_edit_text"
                android:nestedScrollingEnabled="false"></android.support.v7.widget.RecyclerView>
        </net.cachapa.expandablelayout.ExpandableLayout>

        <View
            android:layout_width="130dp"
            android:layout_height="2dp"
            android:layout_marginTop="5dp"
            android:background="#12CED5"></View>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="start">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"

                android:padding="10dp"
                android:text="@string/line_number"
                android:textAllCaps="true"
                android:textColor="#000000" />
        </LinearLayout>



        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="end"
            android:orientation="horizontal"
            android:paddingRight="10dp"
            android:visibility="gone">

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="1"
                android:textAllCaps="true"
                android:textSize="18dp"
                android:textStyle="bold"
                ads:buttonTint="#000000" />

            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"

                android:text="2"
                android:textAllCaps="true"
                android:textSize="18dp"
                android:textStyle="bold"
                ads:buttonTint="#000000" />
        </RadioGroup>

        <Button
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginTop="10dp"
            android:id="@+id/btn_save"
            android:background="@drawable/grd"
            android:text="@string/save"
            android:textColor="#ffffff" />
    </LinearLayout>
</ScrollView>

then in java code

 btnSettings.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PopupWindow window = new PopupWindow(HomeActivity.this);
                window.setFocusable(true);
                window.setContentView(view1);
                window.showAsDropDown(view);
                linearLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (expandableLayout.isExpanded()) {
                            expandableLayout.collapse();
                        } else {
                            expandableLayout.expand();
                        }
                    }
                });

            }
        });