简体   繁体   English

在Android中制作交互式布局的最佳方法

[英]Best way to make an interactive type of layout in android

In my application i have a form to be filled which contains 10-15 fields. 在我的应用程序中,我要填写一个包含10-15个字段的表格。 so i thought making it interactive would make sense rather than showing all the 10-15 fields at a time. 因此,我认为使其具有交互性会比一次展示所有10-15个字段更有意义。

I want it to be like: 我希望它像:

App: question1 as a Text 应用:问题1作为文本

User: answer1 in editText 用户:editText中的answer1

App and User will be their respective ImageViews. 应用程序和用户将是它们各自的ImageView。

depending on the answer, 2nd question will be displayed. 根据答案,将显示第二个问题。

Approach 1: have all the imageViews, TextViews and EditText fields visibility set to false and make them visible after answering the previous question (next question Text will depend on the answer) 方法1:将所有imageViews,TextViews和EditText字段的可见性设置为false,并在回答上一个问题后使其可见(下一个问题文本将取决于答案)

actually i did this but there are few problems: 实际上我做到了,但是有几个问题:

problem 1: i made the layout a ScrollView, so user can scroll to the bottom of the layout(where views are invisible) which tells him that this is a long form with views invisible. 问题1:我将布局制作为ScrollView,因此用户可以滚动到布局的底部(视图不可见),这告诉他这是一个长形,视图不可见。

problem 2: all the questions are TextViews, but all the answer fields are not EditText , some are spinners and some are checkboxes. 问题2:所有问题都是TextViews,但所有答案字段都不都是EditText,有些是微调器,有些是复选框。 so depending on the previous answer if i have to display a spinner or a checkbox wont work(it creates empty space if i skip any invisible view and go for the next view) 因此,取决于上一个答案,如果我必须显示微调框或复选框将无法工作(如果我跳过任何不可见的视图并转到下一个视图,则会创建空白空间)

Approach 2: dynamically create all views (i believe this will take some time, which is a Ux issue again) 方法2:动态创建所有视图(我相信这将需要一些时间,这又是Ux的问题)

is there a better approach to achieve what i wanted?? 有没有更好的方法来实现我想要的? and please let me know how to some my problem 1 and 2 if there is a solution 如果有解决方案,请让我知道如何解决我的问题1和2

Use ViewStub instead of making invisible views. 使用ViewStub而不是创建不可见的视图。 This way it won't occupy any space on the layout. 这样,它不会在布局上占据任何空间。

Well the simplest one would be each "section" of your wizard/questionnaire could be a seperate activity. 好吧,最简单的是向导/问卷的每个“部分”都可能是一项单独的活动。

However I prefer adding and removing the elements from the same activity for this kind of task. 但是,我更喜欢为此类任务从同一活动中添加和删除元素。

The other point you may want to think about is navigation, ie not only going forward to the next question but going back to the previous one. 您可能要考虑的另一点是导航,即不仅前进到下一个问题,而且回到上一个问题。 Keeping track of states in a single activity is not too bad, but then switching to a previous activity can potentially be simpler since each activity just keeps track of its next and previous activities. 跟踪单个活动中的状态并不太糟,但是切换到上一个活动可能会更简单,因为每个活动仅跟踪其下一个和上一个活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM