简体   繁体   English

Android - 垂直方向作品,水平方向空白

[英]Android - vertical orientation works, horizontal orientation blank

I am implementing a ViewPagerIndicator that works as expected in vertical orientation.我正在实现一个在垂直方向上按预期工作的 ViewPagerIndicator。 When I test in horizontal orientation, either by switching at run-time (physically turning the phone) or when the app starts in horizontal mode (phone was horizontal before the app started) I get a blank white space where the ViewPagerIndicator should be.当我在水平方向上进行测试时,无论是通过在运行时切换(物理上转动手机)还是当应用程序以水平模式启动时(手机在应用程序启动之前是水平的),我都会在 ViewPagerIndicator 应该所在的位置得到一个空白区域。 I have a layout/main.xml and layout-land/main.xml with a few buttons that are displaying as expected (stacked vertically in vertical mode, as a grid in horizontal mode).我有一个 layout/main.xml 和 layout-land/main.xml,其中有几个按预期显示的按钮(在垂直模式下垂直堆叠,在水平模式下显示为网格)。 When I press the "edit" button, I launch the edit activity:当我按下“编辑”按钮时,我启动了编辑活动:

public class ATEditActivity extends Activity {
    static final int OFFSCREEN_PAGE_LIMIT = 5;
ViewPager pager = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit);

        int iPage = 2;  // set the page based on caller's intentions
        Bundle bndlExtras = getIntent().getExtras();
        if (bndlExtras != null) {
        iPage = bndlExtras.getInt("PAGE");
        }

        ATViewPagerAdapter adapter = new ATViewPagerAdapter(this);

        pager = (ViewPager) findViewById(R.id.awesomepager);
        pager.setOffscreenPageLimit(OFFSCREEN_PAGE_LIMIT);
        pager.setAdapter(adapter);

        TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.TitlePageIndicator);
        indicator.setViewPager(pager);
        indicator.setCurrentItem(iPage);
    }
}

edit.xml:编辑.xml:

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#FFFFFF"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="0dp"
    android:layout_marginRight="0dp">

<EditText
    android:id="@+id/etName"
    android:inputType="textAutoComplete"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/edit_text"
    android:layout_margin="4dp"
    android:hint="@string/name" />

<com.viewpagerindicator.TitlePageIndicator
    android:id="@+id/TitlePageIndicator"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    style="@style/Widget.MyTitlepageIndicator" />

    <android.support.v4.view.ViewPager
        android:id="@+id/awesomepager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Any thoughts on why the ViewPagerIndicator would not display in horizontal mode?关于为什么 ViewPagerIndicator 不会在水平模式下显示的任何想法? Is more information needed?需要更多信息吗?

You probably need to override onConfigurationChanged() see reference as your app needs to retrieve the resources again and draw everything.您可能需要重写onConfigurationChanged()请参阅参考资料,因为您的应用需要再次检索资源并绘制所有内容。

After three or four days of trying everything I could imagine, I finally decided there must have been something really messed up in my project so I created a new project that only had the minimal amount of code necessary to get the ViewPagerIndicator working.在尝试了三四天我能想象到的一切之后,我最终决定我的项目中一定有什么东西真的搞砸了,所以我创建了一个新项目,它只包含让 ViewPagerIndicator 工作所需的最少代码。 The new project is now working with both orientations "out-of-the-box".新项目现在可以“开箱即用”地使用两个方向。 I have no idea what caused my old project to go haywire with only the horizontal orientation but I will get the new project on track and up to speed in short order now that it is working as expected.我不知道是什么原因导致我的旧项目在只有水平方向时出现 go 乱七八糟的问题,但我会让新项目走上正轨并在短时间内加快速度,因为它正在按预期工作。

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

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