現在、どこから始めればよいかわからないアプリに何かを実装しようとしています。この小さな画像を見てください:
Play ストアでアプリを見つけることができます: https://play.google.com/store/apps/details?id=com.imano.euro2012.row
私のアプリでは、リストビューがあり、アイテムをタップすると、黒いアクティビティを約 3/4 にスライドさせたいと思います。そのアクティビティでは、いくつかのリストビュー項目固有のオプションが必要です。
誰でもこれを解決する方法を知っていますか?
解決:
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 animation not working
追加した
popup.setAnimationStyle(R.style.AnimationPopup);
showAtLocation() 呼び出しの前に、res/anim ディレクトリを作成し、そこに popup_show.xml と popup_hide.xml の 2 つの 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>