Android的卡口与片段 [英] Android TABS with fragments

查看:122
本文介绍了Android的卡口与片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在工作,由有一些标签的GUI的一个小项目。我与碎片的概念很新但似乎他们是在Android标签园景内的最佳实践。我设法code一个简单的标签应用程序,这3个标签之间切换。

I've been working on a small project that consists of a GUI with a number of tabs. I'm quite new with the concept of fragments however it seems that they're a best practice within the android tab landscape. I managed to code a simple tab app, that switches between 3 tabs.

我唯一的问题是,当我尝试把标签在屏幕的底部。当他们在底部,标签控件覆盖(在这种情况下的FrameLayout)容器等没有任何反应,点击各个选项卡时,屏幕保持不变。

The only issue I have is when I try placing the tabs at the bottom of the screen. When they're at the bottom, the tab widget covers the container(framelayout in this case) and so nothing happens, the screen remains the same when clicking the various tabs.

下面的XML布局重新presents良好版本(其中标签是在屏幕的顶部):

The following XML layout represents the good version( where the tabs are at the top of the screen):

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >

            <TabWidget
                android:id="@android:id/tabs"
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0"
                />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="0"/>

            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1"/>
        </LinearLayout>
    </TabHost>
</LinearLayout>

下面的XML布局重新presents不工作,当标签是在屏幕底部的版本:

The following XML layout represents the version that isn't working, when the tabs are at the bottom of the screen:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        >
        <RelativeLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >

            <TabWidget
                android:id="@android:id/tabs"
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                />

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="0dp"
                android:layout_height="0dp"
             />

            <FrameLayout
                android:id="@+android:id/realtabcontent"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
            />
        </RelativeLayout>
    </TabHost>
</LinearLayout>

我改变了layour到RelativeLayout的,并补充如下命令:机器人:layout_alignParentBottom =true添加到tabwidget。有没有人有我如何可以排序这个问题的另一种思路?先谢谢了。

I changed the layour to relativelayout and added this command: android:layout_alignParentBottom="true" to the tabwidget. Does anyone have an alternative idea of how I can sort this issue? Thanks in advance.

推荐答案

在一般使用的标签在屏幕的底部是一个坏的解决方案(见的 Android的设计准则)。

In general using tabs at the bottom of the screen is a bad solution (see Android design guidelines).

有关您的解决方案:把 TabWidget 在查看列表的末尾。因为绘画是一个线工艺和片段这种情况下,你都drowed上TabWidget

For your solution: put TabWidget at the end of list of view. Because of drawing is a line process and fragments this your case are drowed upper TabWidget

这篇关于Android的卡口与片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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