Oliver
Oliver

Reputation: 335

Slide in (over) activity

Currently I'm trying to implement something in my app where I really don't know where to start. Have a look at this little image:

enter image description here

You can find the app in play store here: https://play.google.com/store/apps/details?id=com.imano.euro2012.row

In my app, I have a listview and when i tap on an item I want to slide in the black activity in to about 3/4. In that activity I want to have some llistview item specific options.

Any one knows how to solve this?

Solution:

Thanks to Imran-Khan I got it working. But I think this code is not perfect. I'm not sure if the width and height calculation in the first half of the showPopup() method is correct. And in my solution the popup has on the bottom and on the right a little margin. I don't know right now why this happens. Maybe someone can help...

Here is what I did so far:

First I added the method showpopup(long selectedItem) to my listview:

lv_timer.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) {
            showPopup(id);
        }
});

and the method itself:

private void showPopup(long selectedItem) {
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

    int popupWidth = (width / 4) * 3;
    int popupHeight = height;

    LinearLayout viewGroup = (LinearLayout) findViewById(R.id.ll_timer_prop);
    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.timer_properties, viewGroup);

    final PopupWindow popup = new PopupWindow(this);
    popup.setContentView(layout);
    popup.setWidth(popupWidth);
    popup.setHeight(popupHeight);
    popup.setFocusable(true);

    popup.showAtLocation(layout, Gravity.NO_GRAVITY, width - (width / 4 * 3), 0);

    TextView tv_item = (TextView) layout.findViewById(R.id.tv_item);
    tv_item.setText("Clicked Item ID: " + selectedItem);
}

This is working fine for me.

for the slide in part I've found this thread: PopupWindow animation not working

I added

popup.setAnimationStyle(R.style.AnimationPopup);

before the showAtLocation() call, created a res/anim directory an created two XML files in it: popup_show.xml and popup_hide.xml

popup_show.xml

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

    <scale
        android:fromXScale="0.0" android:toXScale="1.0"
        android:fromYScale="1.0" android:toYScale="1.0"
        android:pivotX="100%" android:pivotY="0%"
        android:duration="@android:integer/config_shortAnimTime"
        />
    <alpha
        android:interpolator="@android:anim/decelerate_interpolator"
        android:fromAlpha="0.0" android:toAlpha="1.0"
        android:duration="@android:integer/config_shortAnimTime"
        />

</set>

popup_hide.xml

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

    <scale
        android:fromXScale="1.0" android:toXScale="0.0"
        android:fromYScale="1.0" android:toYScale="1.0"
        android:pivotX="100%" android:pivotY="0%"
        android:duration="@android:integer/config_shortAnimTime"
        />
    <alpha
        android:interpolator="@android:anim/decelerate_interpolator"
        android:fromAlpha="1.0" android:toAlpha="0.0"
        android:duration="@android:integer/config_shortAnimTime"
        />

</set>

Upvotes: 3

Views: 1583

Answers (3)

gosr
gosr

Reputation: 4708

Funny, I'm actually looking at the same problem right now.

I've found this topic: Android Facebook style slide

Some nice examples in there.

Upvotes: 1

K_Anas
K_Anas

Reputation: 31466

You can use QuickAction For such behaviour, Like shown on third screen

Edit Sorry I have not paid attention for the fact that you want a sliding from right to left effect, But I think you can try to customise slidindrawer in Android API to make slide from right to left.

Upvotes: 1

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132972

You can create this view using custom PopupWindow

see this tutorial for Creating Custom PopupWindow

How to create popups in Android

Upvotes: 2

Related Questions