按 y 翻译时 Listview 被截断

Listview gets cut off when translating by y

注意:这些是随机生成的地址

大家好,Learning Xamarin,我正在尝试向下滚动我的框架布局并显示我的列表视图的搜索栏。这是正在发生的事情:

我对我的布局进行了颜色编码,以查看尺寸是否有问题,但我认为它们没有问题,因为我的橙色布局足够容纳我的两个条目。我是否为此类应用程序使用了错误的布局?如果有任何帮助,我将不胜感激!

这是我的翻译代码:

frameLayout.Animate().TranslationYBy(editSearch.Height).SetDuration(500).Start();

还有我的布局文件:

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipeLayout">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:maxHeight="100dp"
        android:id="@+id/frameLayoutParent"
        android:background="@android:color/holo_green_dark">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/frameLayout"
        android:background="@android:color/holo_green_light">
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="300dp"
                android:background="@android:color/holo_orange_light">
                <Button
                    android:text="Add New Address"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/addNewAddress"
                    android:maxHeight="20dp" />
                </LinearLayout>
        <ListView
            android:paddingTop="50dp"
            android:minWidth="25px"
            android:minHeight="300dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/myListView"
            android:maxHeight="300dp"/>
    </FrameLayout>
<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/editSearch"
    android:hint="Search ZipCodes"
    android:textColor="#000"/>
</FrameLayout>
</android.support.v4.widget.SwipeRefreshLayout>

编辑:

这是我的 OnOptionsItemSelected 代码,我的动画会在此处触发。

public override bool OnOptionsItemSelected(IMenuItem item)
    {
        switch (item.ItemId)
        {
            case Resource.Id.action_search:
                //search icon has been clicked
                if (isAnimating)
                    return true;
                else
                {
                    if (animateBool)
                    {
                        //list view is up
                        animation anim = new animation(myListView, myListView.Height - editSearch.Height);
                        anim.Duration = 500;
                        myListView.StartAnimation(anim);
                        anim.AnimationStart += Anim_AnimationStartDown; //listener for when animation has started
                        anim.AnimationEnd += Anim_AnimationEndDown;
                        classSwipeRefresh.Animate().TranslationYBy(editSearch.Height).SetDuration(500).Start();
                    }
                    else
                    {
                        animation anim = new animation(myListView, myListView.Height + editSearch.Height);
                        anim.Duration = 500;
                        myListView.StartAnimation(anim);
                        anim.AnimationStart += Anim_AnimationStartUp; //listener for when animation has started
                        anim.AnimationEnd += Anim_AnimationEndUp;
                        classSwipeRefresh.Animate().TranslationYBy(-editSearch.Height).SetDuration(500).Start();
                    }
                    animateBool = !animateBool;
                    return true;
                }
            default:
                return base.OnOptionsItemSelected(item);
        }
        
    }

Learning Xamarin and I am trying to scroll my Frame Layour down and reveal a search bar for my list view. Here is what is happening:

我用你的代码测试了,但是在SwipeRefreshLayout__Refresh事件中按Y翻译没有问题。

 public class MainActivity : AppCompatActivity
{
    string[] items;
    ListView listview1;
    SwipeRefreshLayout swiplayout;
    FrameLayout framelayout;
    EditText edittext;
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.activity_main);
        listview1 = FindViewById<ListView>(Resource.Id.myListView);
        swiplayout = FindViewById<SwipeRefreshLayout>(Resource.Id.swipeLayout);
        framelayout = FindViewById<FrameLayout>(Resource.Id.frameLayout);
        edittext = FindViewById<EditText>(Resource.Id.editSearch);
        swiplayout.Refresh += Swiplayout_Refresh;
        items = new string[] { "Vegetables", "Fruits", "Flower Buds", "Legumes", "Bulbs", "Tubers" };
        listview1.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, items);
    }

    private void Swiplayout_Refresh(object sender, EventArgs e)
    {
        framelayout.Animate().TranslationYBy(edittext.Height).SetDuration(500).Start();
    }

  
}

这是我的截图:

如果你想过滤ListView,我建议你可以使用工具栏中的SearchView来过滤listview数据,请看这个示例:

https://github.com/Cheesebaron/SearchView-Sample/tree/master/SearchViewSample