片段的元素被顶部的tabLayout阻挡,我似乎无法将这些元素保留在标签下方。
每个标签都是它自己的片段。
MainActivity.XML
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
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:background="#ffffff"
android:fillViewport="false"
android:label="Journal Entry"
tools:context="edu.tp.sghealthapp.HomeActivity">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/tab">
<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="@layout/layout_tabbar"/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#339999"
android:id="@+id/tabLayout"
app:tabMode ="fixed"
app:tabGravity="fill">
</android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager"></android.support.v4.view.ViewPager>
fragment_glucoseEntry.XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="edu.tp.sghealthapp.GlucoseFragment"
android:layout_alignParentBottom="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1"
android:layout_below="@+id/viewPager"
android:gravity="top">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:stretchColumns="0,1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/titlet"
android:layout_span="2"
android:paddingLeft="4dp"
android:text="Glucose Measurement"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1">
<EditText
android:id="@+id/glucoseET"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:ems="10"
android:hint="Enter glucose reading (mmol/dl)"
android:inputType="numberDecimal"
android:singleLine="true" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:stretchColumns="0,1">
<TextView
android:id="@+id/glucoseTimeTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:paddingLeft="4dp"
android:text="Time of Glucose Measurement"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1">
<EditText
android:id="@+id/glucoseTimeET"
android:layout_width="wrap_content"
android:layout_span="2"
android:focusable="false"
android:hint="Select time..."
android:inputType="number"
android:onClick="onClickShowTimeDialogue" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1">
<TextView
android:id="@+id/glucoseDateTV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:paddingLeft="4dp"
android:text="Date of Glucose Measurement"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1">
<EditText
android:id="@+id/glucoseDateET"
android:layout_width="wrap_content"
android:layout_span="2"
android:focusable="false"
android:hint="Select Date..."
android:inputType="date"
android:onClick="onClickShowTimeDialogue" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="20dp">
<Button
android:id="@+id/btnCancel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_weight="1"
android:background="@android:color/holo_red_light"
android:nestedScrollingEnabled="false"
android:onClick="returnHomeOnClick"
android:text="Cancel" />
<Button
android:id="@+id/btnSaveEntry"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_weight="1"
android:background="@android:color/holo_green_light"
android:text="Save"
android:layout_marginLeft="10dp"/>
</TableRow>
</TableLayout>
</FrameLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
Toolbar mToolBar;
TabLayout mTabLayout;
ViewPager mViewPager;
Button mBtnSaveEntry;
EditText mGlucose, mGlucoseTime, mMealTime;
TableRow t1;
AutoCompleteTextView mTxtFood, mTxtFood2, mTxtFood3;
RadioGroup mRadioGrp;
RadioButton mSelectedRadio;
Helper helper = new Helper();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_entry);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mToolBar = (Toolbar) findViewById(R.id.tabBar);
setSupportActionBar(mToolBar);
mTabLayout = (TabLayout) findViewById(R.id.tabLayout);
mViewPager = (ViewPager) findViewById(R.id.viewPager);
ViewPagerAdapter pgAdapter = new ViewPagerAdapter(getSupportFragmentManager());
pgAdapter.addFragments( new GlucoseFragment(), "Glucose Entry");
pgAdapter.addFragments(new FoodEntryFragment(), "Food Entry");
mViewPager.setAdapter(pgAdapter);
mTabLayout.setupWithViewPager(mViewPager);
}
GlucoseFragment.java
public class GlucoseFragment extends Fragment {
public GlucoseFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_glucose, container, false);
}
}
答案 0 :(得分:2)
尝试使用android.support.design.widget.CoordinatorLayout
替代RelativeLayout
然后在您的viewpager中添加app:layout_behavior="@string/appbar_scrolling_view_behavior"
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
....
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
答案 1 :(得分:1)
我认为导致此问题的是viewpager对齐方式。尝试将其更改为此。
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewPager"
android:layout_below="@id/tablayout"
></android.support.v4.view.ViewPager>
希望它有效。 THANKYOU
答案 2 :(得分:1)
将AppPar对齐AppBarLayout下方。当您使用相对布局时,您需要在viewPager属性中添加一行,即android:layout_below =&#34; @ + id / tab&#34;