首页 > 解决方案 > 创建一个活动以提供多个选项以供选择

问题描述

我是新的 Xamarin android 开发。如果问题听起来很简单,请原谅。我正在创建一个表单,我需要为用户提供选择多个选项的选项,类似于复选框组。选项的数量可能更大,例如 10-20。我不是要使用哪个控件或布局,以便用户轻松阅读和选择选项。我尝试使用线性和垂直选项进行布局,但这看起来不太好。此外,如何基于某些数据源以编程方式创建这些选项。请建议我设计这个的最佳方法。任何帮助将不胜感激。这是我的 axml 中的片段

我尝试使用 LinearLayout 并使用了复选框控件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"          
android:layout_width="match_parent"
android:layout_height="match_parent">
 <CheckBox
     android:id="@+id/blogging"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="Blog"/>
  <CheckBox
     android:id="@+id/game"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"               
     android:text="Game" />                 

标签: xamarinxamarin.android

解决方案


Found what I was looking for. It's called the Switch tool. So to provide settings page like options, I'll use this instead of checkboxes
<Switch
   android:id="@+id/blogging"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:theme="@style/Widget.AppCompat.CompoundButton.Switch"
   android:hint="Blog"
  />
<Switch
   android:id="@+id/game"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:theme="@style/Widget.AppCompat.CompoundButton.Switch"             
   android:text="Game" />

推荐阅读