Sunday, 27 March 2016

XML : Elements being blocked by tabLayout

Elements of fragments are getting blocked by the tabLayout on the top and I cannot seem to keep the elements below the tabs.

Each tab is it's own fragment.

Any help getting the elements to stick below the tabs is appreciated

enter image description here

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);          }        }    

No comments:

Post a Comment