![](/img/trans.png)
[英]Difference between android:orientation=“vertical” vs android:orientation=“horizontal”
[英]Android - vertical orientation works, horizontal orientation blank
我正在实现一个在垂直方向上按预期工作的 ViewPagerIndicator。 当我在水平方向上进行测试时,无论是通过在运行时切换(物理上转动手机)还是当应用程序以水平模式启动时(手机在应用程序启动之前是水平的),我都会在 ViewPagerIndicator 应该所在的位置得到一个空白区域。 我有一个 layout/main.xml 和 layout-land/main.xml,其中有几个按预期显示的按钮(在垂直模式下垂直堆叠,在水平模式下显示为网格)。 当我按下“编辑”按钮时,我启动了编辑活动:
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);
}
}
编辑.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>
关于为什么 ViewPagerIndicator 不会在水平模式下显示的任何想法? 需要更多信息吗?
您可能需要重写onConfigurationChanged()
请参阅参考资料,因为您的应用需要再次检索资源并绘制所有内容。
在尝试了三四天我能想象到的一切之后,我最终决定我的项目中一定有什么东西真的搞砸了,所以我创建了一个新项目,它只包含让 ViewPagerIndicator 工作所需的最少代码。 新项目现在可以“开箱即用”地使用两个方向。 我不知道是什么原因导致我的旧项目在只有水平方向时出现 go 乱七八糟的问题,但我会让新项目走上正轨并在短时间内加快速度,因为它正在按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.