【问题标题】:How to make a dropdown list like spinner Android but in Xamarin Forms?如何在 Xamarin Forms 中制作像 Spinner Android 这样的下拉列表?
【发布时间】:2023-03-07 09:49:01
【问题描述】:

我需要你的帮助!

我想在 Xamarin Forms 中创建一个下拉列表。我的 xaml 中有一个按钮,当有一个点击事件时,我希望在这个按钮的底部出现一个列表。看图片!

提前谢谢你!

List not visible/List visible and on foreground when image clicked

【问题讨论】:

    标签: android spinner xamarin.forms dropdown dropdownbox


    【解决方案1】:
    yourlayout.xml
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="click"
        android:id="@+id/click"/>
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        android:layout_below="@+id/click"
        android:paddingLeft="30dp"
        android:paddingRight="30dp"
        android:id="@+id/list"/>
    </RelativeLayout>
    
    on your activity 
    ListView list = (ListView) findViewById(R.id.list);
    final Button click = (Button) findViewById(R.id.click)
     click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                list.setVisibility(list.getVisibility() == View.INVISIBLE ? View.VISIBLE : View.INVISIBLE);
    });
    

    【讨论】:

    • 谢谢,但我认为使用此解决方案,列表视图不会出现在前台。此外,如果可能的话,我想要一个 Xamarin 表单的解决方案(在 PCL 项目中)。
    猜你喜欢
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 2011-02-23
    • 2012-03-16
    • 2014-01-03
    • 2021-03-10
    相关资源
    最近更新 更多