0

基于 ADT 中默认的“固定选项卡 + 滑动”活动,我有一个FragmentActivity带有FragmentPagerAdapter.

非常简单(仅根据FragementPagerAdapter调用位置返回某个片段),目前它FragmentActivity本身也是 Eclipse 提供的“示例”代码的默认设置。“有趣”的部分附在最后,但这就是它的外观(显然为了提问目的而简化了)

现在在一个不同的片段中,我有一个按钮,应该显示一些信息和一张图片/图片:一些不真正属于选项卡式视图的东西。

最好的方法是什么?

我考虑过要么开始一项新活动,但不鼓励使用片段构建,因此我放弃了该选项。然后我可以制作一个“随机”片段来显示,但我不确定如何在寻呼机方面实现它->这实际上可能是最好的方法。

我能想出的是展示一个DialogFragment. 我实际上是这样实现的:

首先用这个创建一个DialogFragment onCreateView

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    LinearLayout v = (LinearLayout) inflater.inflate(R.layout.entry, container, false);
    //set image
    return v;
}

并像这样显示它:

fragment.show(getSupportFragmentManager(), "dialog");

xml 是 stackoverflow 上建议的简单线性布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:minWidth="1000dp"  
    android:minHeight="1000dp"> 

    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:contentDescription="@string/image_desc" 
         />

 </LinearLayout> 

这里的问题是,虽然这显示得很好,但似乎在图片上方添​​加了一些东西(寻呼机的标题栏?不确定):

很难看,但我相信它直接符合 pager-fragment-titles 的底部,所以我似乎“继承”了一些功能?

当前基本代码

从 onCreate 中FragmentActivity

setContentView(R.layout.activity_main);
...

mSectionsPagerAdapter = new SectionsPagerAdapter(
    getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);

SectionsPagerAdapter是一个返回一些片段的内部类FragmentPagerAdapter,没什么有趣的

activity_main再次非常标准:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

<!--
This title strip will display the currently visible page title, as well as the page
titles for adjacent pages.
-->

    <android.support.v4.view.PagerTitleStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#555555"
        android:paddingBottom="4dp"
        android:paddingTop="4dp"
        android:textColor="#fff" />

</android.support.v4.view.ViewPager>
4

1 回答 1

1

在我看来,使用 dialogFragment 确实是一个不错的方法,而且它肯定是最简单的方法之一。

此外,如果合适的话,您可以让您的 dialogFragment 全屏显示,如下所示:在 values/styles.xml 中创建自定义对话框样式

<!-- DIALOG STYLE -->
<style name="Your.Dialog" parent="android:Theme.Holo.Dialog" >
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowIsFloating">false</item>
</style>

然后设置调用片段的样式,如下所示:

    myDialogFragment dialog = new myDialogFragment ();
    dialog.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Your_Dialog );
    dialog.show(getSupportFragmentManager(), "fragment_tag");
于 2013-11-03T14:27:59.040 回答