【问题标题】:Creating an activity to provide multiple options to select创建一个活动以提供多个选项以供选择
【发布时间】:2019-01-12 07:47:20
【问题描述】:

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

我尝试过使用 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" />                 

【问题讨论】:

  • 您能否直观地向我展示您想要实现的目标,因为您的问题令人困惑
  • @G.hakim 感谢您的回复。这基本上是一个设计问题。我必须设计一个用户界面,用户可以在其中选择多个选项。选项的数量可能很大,例如 15-20,并且会占用屏幕上的大量空间。我在 LinearLayout 中添加了多个复选框。而且看起来不太好。我正在寻找我还有哪些其他选择? xamarin 工具包中是否有内置控件/工具。任何指向示例代码库的指针都将不胜感激。类似于 iOS/android 应用程序中的设置页面,其中使用查看选项列表,他/她可以打开/关闭。
  • Xamarin.Android 只是带有 C# 代码(而不是 java)的 Native Android,它只有 Native Android 中可用的东西,我不知道您所说的任何此类控件!跨度>
  • @G.hakim 感谢您的回复。我想我找到了我要找的东西。它被称为开关控制。我正在使用它来创建页面等设置。这是其他人正在寻找它的示例代码 sn-p。

标签: xamarin xamarin.android


【解决方案1】:
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" />

【讨论】:

  • 请尝试将其标记为答案,它将帮助其他有类似问题的人。
  • 当然@LeonLu-MSFT。它不允许我投票给我的答案:)
猜你喜欢
  • 1970-01-01
  • 2011-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-17
相关资源
最近更新 更多