I have thoroughly searched already and then decided to ask here. I am trying to find an example of implementing a button
when a user clicks, listview
appears and when user clicks the button
again, the listview
disappears in xamarin.android
答案 0 :(得分:1)
Android.Views.View.IOnClickListener
。点击按钮可更改ListView的可见性
private bool _isShowing = false;
//Don't forget to initialize those in your OnCreate
private ListView _listView;
private Button _button;
public void OnClick (View v)
{
_isShowing = !_isShowing;
_listView.Visibility = _isShowing ? ViewStates.Visible : ViewStates.Gone;
}
//Inside your OnCreate, after initializing you button and your ListView
_button.SetOnClickListener(this);
要使用流畅的动画,只需将其添加到.axml:
android:animateLayoutChanges="true"
我强烈建议使用MVVM方法,但由于你没有提到任何框架,这样就可以了。