material.ioのList popup window menus
でリスト表示のアニメーションを消去したいのですが、listPopupWindow.animationStyle = 0
とやってもうまく消えてくれません。
listPopupWindow.animationStyle = 0
で、
ListPopupWindow
のsetAnimationStyle
が呼ばれその内部で
PopupWindow
に(mPopup)setAnimationStyle
でanimationStyle
をセットしています。
PopupWindow
のsetAnimationStyle
には、ドキュメントにアニメーション無しは0(0 for no animation
)と書かれています。
どなたかお知恵を頂けないでしょうか?
public class ListPopupWindow implements ShowableListMenu { PopupWindow mPopup; /** * Set an animation style to use when the popup window is shown or dismissed. * * @param animationStyle Animation style to use. */ public void setAnimationStyle(@StyleRes int animationStyle) { mPopup.setAnimationStyle(animationStyle); } public class PopupWindow { /** * <p>Change the animation style resource for this popup.</p> * * <p>If the popup is showing, calling this method will take effect only * the next time the popup is shown or through a manual call to one of * the {@link #update()} methods.</p> * * @param animationStyle animation style to use when the popup appears * and disappears. Set to -1 for the default animation, 0 for no * animation, or a resource identifier for an explicit animation. * * @see #update() */ public void setAnimationStyle(int animationStyle) { mAnimationStyle = animationStyle; }
Kotlin
1class FirstFragment : Fragment() { 2 3 override fun onCreateView( 4 inflater: LayoutInflater, container: ViewGroup?, 5 savedInstanceState: Bundle? 6 ): View? { 7 // Inflate the layout for this fragment 8 val view = inflater.inflate(R.layout.fragment_first, container, false) 9 10 val listPopupWindowButton = view.findViewById<Button>(R.id.list_popup_button) 11 val listPopupWindow: ListPopupWindow = ListPopupWindow(requireContext(), null, R.attr.listPopupWindowStyle) 12 13 // Set button as the list popup's anchor 14 listPopupWindow.anchorView = listPopupWindowButton 15 16 // Set list popup's content 17 val items = listOf("Option 1", "Option 2", "Option 3") 18 val adapter = ArrayAdapter(requireContext(), R.layout.list_popup_window_item, items) 19 listPopupWindow.setAdapter(adapter) 20 21 // Set list popup's item click listener 22 listPopupWindow.setOnItemClickListener { parent: AdapterView<*>?, view: View?, position: Int, id: Long -> 23 // Respond to list popup window item click. 24 25 // Dismiss popup. 26 listPopupWindow.dismiss() 27 } 28 29 // Show list popup window on button click. 30 listPopupWindowButton.setOnClickListener { v: View? -> listPopupWindow.show() } 31 32 // アニメーションがオフにならない??? 33 listPopupWindow.animationStyle = 0 34 35 return view 36 }
XML
1layout/list_popup_window_item 2 3<TextView xmlns:android="http://schemas.android.com/apk/res/android" 4 android:layout_width="match_parent" 5 android:layout_height="wrap_content" 6 android:ellipsize="end" 7 android:maxLines="1" 8 android:padding="16dp" 9 android:textAppearance="?attr/textAppearanceSubtitle1" />
XML
1fragment_first 2 3<?xml version="1.0" encoding="utf-8"?> 4<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 5 xmlns:app="http://schemas.android.com/apk/res-auto" 6 xmlns:tools="http://schemas.android.com/tools" 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 tools:context=".FirstFragment"> 10 11 <Button 12 android:id="@+id/list_popup_button" 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 app:layout_constraintBottom_toTopOf="parent" 16 app:layout_constraintLeft_toLeftOf="parent" 17 app:layout_constraintRight_toRightOf="parent" 18 app:layout_constraintTop_toTopOf="parent" 19 android:text="show_menu"/> 20 21</androidx.constraintlayout.widget.ConstraintLayout>
あなたの回答
tips
プレビュー