3

目前我正在尝试在我的应用程序中实现一些我真的不知道从哪里开始的东西。看看这个小图:

在此处输入图像描述

您可以在 Play 商店中找到该应用程序:https: //play.google.com/store/apps/details?id=com.imano.euro2012.row

在我的应用程序中,我有一个列表视图,当我点击一个项目时,我想将黑色活动滑入大约 3/4。在那个活动中,我想要一些 llistview 项目特定的选项。

有谁知道如何解决这个问题?

解决方案:

感谢 Imran-Khan,我得到了它的工作。但我认为这段代码并不完美。我不确定 showPopup() 方法前半部分的宽高计算是否正确。在我的解决方案中,弹出窗口在底部和右侧有一点边距。我现在不知道为什么会这样。也许有人可以帮助...

这是我到目前为止所做的:

首先,我将方法 showpopup(long selectedItem) 添加到我的列表视图中:

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

和方法本身:

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);
}

这对我来说很好。

对于部分幻灯片,我发现了这个线程:PopupWindow 动画不起作用

我添加了

popup.setAnimationStyle(R.style.AnimationPopup);

在调用 showAtLocation() 之前,创建了一个 res/anim 目录并在其中创建了两个 XML 文件:popup_show.xml 和 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>
4

3 回答 3

2

您可以使用自定义PopupWindow创建此视图

请参阅本教程以创建自定义 PopupWindow

如何在 Android 中创建弹出窗口

于 2012-06-23T19:11:38.813 回答
1

您可以将QuickAction用于此类行为,如第三个屏幕上所示

编辑 对不起,我没有注意你想要从右到左滑动的效果,但我认为你可以尝试在 Android API 中自定义 slidindrawer 以从右到左滑动。

于 2012-06-23T18:56:33.230 回答
1

有趣的是,我现在实际上正在研究同样的问题。

我找到了这个话题: Android Facebook style slide

里面有一些很好的例子。

于 2012-06-23T19:23:42.207 回答