安卓:我怎样才能浏览从一个"详情"另一个"详情",具有&QUOT同时,截至"按钮返回到"硕士"上市? [英] Android: How can I navigate from one "detail" to another "detail", while having the "Up" button go back to the "Master" list?

查看:185
本文介绍了安卓:我怎样才能浏览从一个"详情"另一个"详情",具有&QUOT同时,截至"按钮返回到"硕士"上市?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序主从模式,但我希望细节能够切换视图。我想尽可能多的空间储存尽可能使内容很不错,宽敞。 如何定位从一个细节的另一个细节,而具有向上按钮返回到大师名单?(见的详细信息1的箭头,详细2我的照片。)

I have a master-detail pattern in my app, but I want the detail to be able to switch views. I want to save as much space as possible so the "content" is nice and spacious. How can I navigate from one "detail" to another "detail", while having the "Up" button go back to the "Master" list? (See the arrow between "Detail 1" and "Detail 2" on my picture.)

我已经花了很多时间思考这一点,研究这样做的各种方法,甚至问了一个堆栈溢出问题(<一href="http://stackoverflow.com/questions/31017969/how-to-do-something-like-drop-down-navigation-in-android-since-it-looks-like-it">How像做下拉导航Android中(因为它看起来像它已成为德precated?)),我仍然在等待一个有用的答案。即使我有这个问题回答,我不知道它会真的有这样的主从流工作。

I've spent a lot of time thinking about this and researching various methods of doing this, and even asked a stack overflow question (How to do something like Drop Down Navigation in Android (since it looks like it has become deprecated?)) and I am still waiting for a helpful answer. Even if I got that question answered, I'm not sure it would really work with Master Detail flow like this.

如果主详细不起作用,什么是做到这一点的UI布局我有什么想法?有没有人做过这样的事情之前,最好的方法是什么?谢谢!

If Master-Detail doesn't work, what would be the best way to accomplish this UI layout I have in mind? Has anyone done something like this before? Thanks!

编辑:理想情况下,我也想用户能够设置一个默认的观点(详细信息1或细节2),这将是第一个屏幕单击主列表上的项目后,拿出

编辑2:我有一个主意,用一个ViewPager详细1和2,细节我不知道这是否会工作,但之间进行转换。或者,我可以让细节2的另一项活动折扣详细1,但我不想让空间在我的内容区域的按钮。 我真的不能用一个抽屉,因为抽屉图标,在同一个地方都按向上箭头。我在一个损失,因为我觉得抽屉是最适合这种情况,但我因为我已经使用的向上箭头无法使用它。

Edit 2: I had an idea to use a ViewPager to transition between Detail 1 and Detail 2. I'm not sure if it will work though. Or, I could make Detail 2 an additional activity off of Detail 1, but I don't want to make space for a button in my "content" area. I can't really use a drawer because the drawer icon goes in the same place as the "Up" arrow. I'm at a loss because I think the drawer is best for this situation, but I can't use it because I am already using the "Up" arrow.

编辑3:我试图想出一个应用程序,做了我想做的,我觉得点燃这是否良好。它有一本书的每一页之间切换,但首先你要选择一本书。当你在一本书上的Kindle,操作栏和放大器;抽屉式导航栏更改为白色和导航抽屉的第一项是库。点击库带你到一个黑色的操作栏和黑色导航抽屉与不同的菜单项完全不同的活动。所以,我想,这大概的路线,我应该采取。我也许应该不再有向上按钮,只需使用抽屉里的第一个项目,作为一个向上按钮。我仍然有兴趣学习,并考虑我所有的选择,虽然。

Edit 3: I tried to think of an app that did what I'm trying to do, and I think "Kindle" does this well. It has to switch between every page of a book, but first you have to choose a book. While you're in a book on Kindle, the Action Bar & Navigation Drawer changes to white and the Navigation Drawer's first item is "Library." Clicking on "Library" takes you to a completely different activity with a black action bar and black navigation drawer with different menu items. So, I think this is probably the route I should take. I should probably no longer have an "Up" button, and just use the first item of the drawer to act as an "Up" button. I am still interested in learning and considering all of my options, though.

推荐答案

下面是另一种使用片段 ViewPager (因为他们通常可以结束更多的样板codeS)。

Here's an alternative to using Fragments and ViewPager (as they could usually end in more boilerplate codes).

莱所有细节的看法,在一个 layout.xml 并通过 View.setVisibility切换它们的可见性()在一个按钮的点击。您可以标记该按钮为继续,下一步,或什么的。其主要思想是让用户知道,他们是在尽管屏幕的变化相同的情况下。

Lay all of your detail's view in one layout.xml and toggle their visibility via View.setVisibility() upon a click of a button. You can label this button as "Continue", "Next", or whatever. The main idea is to make the user aware that they're on the same context despite the change of screen.

下面是你应该如何安排的说明你的细节的 layout.xml

Here's an illustration on how you should arrange your detail's layout.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/layout_page_1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="visible">

        <!-- Put your detail 1 content here -->

    </LinearLayout>

    <LinearLayout
        android:id="@+id/layout_page_2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone">

        <!-- Put your detail 2 content here -->

    </LinearLayout>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Continue"
        android:id="@+id/bt_continue"/>

</RelativeLayout>

正如我所说的,这个想法是切换 layout_page_1 layout_page_2 bt_continue 得到了点:

@Override
public void onClick(View v) {
    if(v.getId() == R.id.bt_continue) {
        layoutPage1.setVisibility(View.INVISIBLE);
        layoutPage2.setVisibility(View.GONE);
    }
}

通过这个逻辑,你也可以实现一个previous按钮导航回到你的细节的第一页。

With this logic, you could also implement a "Previous" button to navigate back to the first page of your detail.

如果您希望您的用户能够设置一个默认视图那么这是一件容易的事。只是保存 INT 共享preferences 这将重新present的页面,将开设了 - 这是将被设置为 View.VISIBLE 视图 - 第一次用户打开详细视图

If you want your user to able to set a default view then that's easy too. Just save an int in your SharedPreferences which will represent the page that will be "opened" - that is the view that will be set to View.VISIBLE - the first time your user opens the detail view.

这篇关于安卓:我怎样才能浏览从一个&QUOT;详情&QUOT;另一个&QUOT;详情&QUOT;,具有&QUOT同时,截至&QUOT;按钮返回到&QUOT;硕士&QUOT;上市?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆