Slide in (slide through) the activity
Currently I’m trying to implement something in my app that I don’t really know where to start.
Take a look at this little picture:
You can find the app on the 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 the black activity into about 3/4. In this activity, I want some llistview project-specific options.
Does anyone know how to fix it?
Solution:
Thanks to Imran-Khan, I got it running.
But I don’t think this code is perfect. I’m not sure if the width and height calculations for the first half of the showPopup() method are correct. In my solution, the popup has a bit of margin at the bottom and right. I don’t know why this is right now. Maybe someone can help….
Here’s what I’ve done 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);
}
That’s fine for me.
For partial slides, I found this thread: PopupWindow animation not working
I added
popup.setAnimationStyle(R.style.AnimationPopup);
Before the showAtLocation() call, a res/anim directory is created and two XML files are created 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>
Solution
You can create this View with a custom PopupWindow
See this tutorial to create a custom pop-up