在Android 4.0的困境标签 [英] Tabs on android 4.0 woes
问题描述
我想在Android 2.2使用标签 - 4.0。我已经扩展<一个href=\"http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html\"相对=nofollow>这个演示:<一href=\"http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html\" rel=\"nofollow\">http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html搭配:
I'm trying to use tabs on android 2.2 - 4.0. I've extended this demo: http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html with:
TabSpec ts = mTabHost.newTabSpec("randomTab");
Intent intent = new Intent();
intent.setClass(this, FragActiv.class);
ts.setContent(intent);
ts.setIndicator("randomTab");
mTabManager.addTab(ts, FragActiv.class, new Bundle());
但我不知道该怎么添加的 onTabChanged 的,所有的魔法发生在演示。
But I don't know what to add to onTabChanged, where all the magic happens in the demo.
的我需要做的是:的结果
我有一个 ListFragment
并单击某个项目时,应显示在的小屏幕/纵向在单独的屏幕细节的或,在的大屏幕/横向的,显示与在同一画面上的细节片段。我可以解决此片段用或者我应该尝试 FragmentActivities
正常工作?
What I need to do is:
I have a ListFragment
and when an item is clicked, it should display details in a separate screen on a small screen/portrait orientation or, on a large screen/landscape orientation, display a fragment with the details on the same screen. Can I work around this with Fragments or should I try to get FragmentActivities
working properly?
通过遵循这个例子:<一href=\"http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentLayoutSupport.html\"相对=nofollow>例如,我能够实例化的 FragmentActivity 的,但它占用了整个屏幕,而不仅仅是选项卡菜单中。
By following this example: example, I was able to instantiate a FragmentActivity, but it takes up the whole screen, rather than just the area under the tab menu.
是否有任何机会的使用活动(或FragmentActivities),而不是片段,标签内容
推荐答案
有没有必要做我想要的东西(使用TabActivity作为标签内容)的。我已经通过有我tabContent内的两个集装箱,一个用于ListView的片段,一个用于细节片段解决了这个问题。这是我现在的布局:
There was no need of doing what I wanted (using a TabActivity as content of a tab). I've solved the problem by having two containers inside my tabContent, one for the ListView fragment and one for the details fragment. Here is my layout now:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" />
</HorizontalScrollView>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:fadingEdge="none" >
<FrameLayout
android:id="@+android:id/realtabcontent"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1" />
<FrameLayout
android:id="@+android:id/details_container"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="1"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>
首先, details_container 已经一去不复返了。您可以用它如下:
Initially, details_container is GONE. You can use it as following:
ft.replace(R.id.details_container, detailsFragment);
FrameLayout detailsLayout = (FrameLayout) mActivity.findViewById(R.id.details_container);
detailsLayout.setVisibility(View.VISIBLE);
这篇关于在Android 4.0的困境标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!