Android选项卡视图-是否已选中?
我的总体目标是根据所选页面显示和隐藏布局 我的问题是: 只有案例1有效 这是唯一显示和隐藏布局的情况。案例0、案例2和案例3不会显示/隐藏布局,但它们都会正确记录.dPageSelected、String.valueofposition 我做错了什么 我在xml文件中创建了布局:Android选项卡视图-是否已选中?,android,android-layout,android-activity,switch-statement,case,Android,Android Layout,Android Activity,Switch Statement,Case,我的总体目标是根据所选页面显示和隐藏布局 我的问题是: 只有案例1有效 这是唯一显示和隐藏布局的情况。案例0、案例2和案例3不会显示/隐藏布局,但它们都会正确记录.dPageSelected、String.valueofposition 我做错了什么 我在xml文件中创建了布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.and
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity$PlaceholderFragment">
<TextView android:id="@+id/section_label" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<GridLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:rowCount="4"
android:columnCount="5"
android:id="@+id/HomeFrag"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Home"
android:id="@+id/textView2" />
</GridLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/SearchFrag"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Search"
android:id="@+id/textView4" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/SettingFrag"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Setting"
android:id="@+id/textView5" />
</LinearLayout>
</FrameLayout>
</RelativeLayout>
您是否使用FrameLayout在xml文件中包含3个布局?没有,我只是在根相对布局下添加了布局。我将尝试框架布局并报告我的result@headuck这没什么区别。只有案例1适用于更改布局。您可以发布完整的xml吗?你的意思是案例0、2和3的屏幕没有变化,只看到案例1的SearchFrag布局?@headuck I用整个XML更新了帖子。如果我滑动到第三个选项卡Case 2,则不会发生任何变化。如果转到第二个选项卡案例1->第三个选项卡案例2->第二个选项卡案例1,则第二个选项卡布局会发生变化。如果我返回到第三个选项卡,应用程序启动时的原始布局仍会显示。
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
public void onPageSelected(int position) {
switch (position){
case 0: {
Log.d("PageSelected:", String.valueOf(position));
findViewById(R.id.HomeFrag).setVisibility(View.VISIBLE);
findViewById(R.id.SearchFrag).setVisibility(View.INVISIBLE);
findViewById(R.id.SettingFrag).setVisibility(View.INVISIBLE);
break;
}
case 1: {
Log.d("PageSelected:", String.valueOf(position));
findViewById(R.id.HomeFrag).setVisibility(View.INVISIBLE);
findViewById(R.id.SearchFrag).setVisibility(View.VISIBLE);
findViewById(R.id.SettingFrag).setVisibility(View.INVISIBLE);
break;
}
case 2: {
Log.d("PageSelected:", String.valueOf(position));
findViewById(R.id.HomeFrag).setVisibility(View.INVISIBLE);
findViewById(R.id.SearchFrag).setVisibility(View.INVISIBLE);
findViewById(R.id.SettingFrag).setVisibility(View.VISIBLE);
break;
}
case 3: {
Log.d("PageSelected:", String.valueOf(position));
}
}
}
});