2016-03-27 11 views
0

フラグメントの要素が上部のtabLayoutによってブロックされているため、タブの下に要素を保持できないようです。要素がtabLayoutによってブロックされています

各タブはそれ自身の断片です。

タブの下に固執する要素を取得してすべてのヘルプは高く評価され

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

    } 

答えて

1

AppBarLayoutの下にViewPagerを揃えます。あなたは相対的なレイアウトを使用すると、あなたはviewPager properiesすなわちアンドロイドに行を追加する必要がありますlayout_below =「@ + ID /タブ」

+0

これは私をとても助けました、ありがとう! – Isaac

+0

ウィジェットを参照するために@ + id/tabを使用しないでください。@ id/tabを代わりに使用してください。 – Ritesh

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> 

希望します。ありがとうございました

2

RelativeLayoutの代替としてandroid.support.design.widget.CoordinatorLayoutを使用してみてくださいそして、あなたのviewpagerに

<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> 
app:layout_behavior="@string/appbar_scrolling_view_behavior"を追加
関連する問題