2017-03-04 110 views
-1

我有一個應用程序Navigation Drawer和一個片段ScrollViewwidgetsAndroid:應用程序欄上的片段

問題是片段小部件出現在應用程序欄上。是否可以調整片段佈局,以便在應用欄下啓動?

預先感謝您!

截圖: enter image description here

這是我的片段XML

<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" 
    tools:context="it.bitrack.fabio.bitrack.AssetView" 
    android:id="@+id/assetView_relative_layout"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:weightSum="1"> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textPersonName" 
       android:text="17AB05" 
       android:ems="10" 
       android:id="@+id/assetCode" /> 

      <Button 
       android:text="Fetch data" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/fetchUpdateButton" /> 

      <com.github.mikephil.charting.charts.LineChart 
       android:id="@+id/lineChart" 
       android:layout_width="match_parent" 
       android:layout_height="250dp" /> 

      <TextView 
       android:layout_width="match_parent" 
       android:id="@+id/selectionTextView" 
       android:layout_height="wrap_content" 
       android:text="Nothing selected" /> 

     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 

這是我的主要活動XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:openDrawer="start"> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <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" 
     tools:context="it.bitrack.fabio.bitrack.AssetView" 
     android:id="@+id/container"> 
    </RelativeLayout> 

    <android.support.design.widget.NavigationView 
     android:id="@+id/nav_view" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:fitsSystemWindows="true" 
     app:headerLayout="@layout/nav_header_main" 
     app:menu="@menu/activity_main_drawer" /> 

</android.support.v4.widget.DrawerLayout> 

這是我的應用程序欄XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 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" 
    android:fitsSystemWindows="true" 
    tools:context="it.bitrack.fabio.bitrack.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 

    </android.support.design.widget.AppBarLayout> 

    <include layout="@layout/content_main" /> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     app:srcCompat="@android:drawable/ic_dialog_email" /> 

</android.support.design.widget.CoordinatorLayout> 
+1

你應該設置layout_below或layout_above爲ID容器的佈局之間的活動XML的容器和appbar –

+0

@CanberkÖzçelik我試過,但它沒有工作: user1060551

+0

使用主要活動@ layout/content_main設置框架佈局 –

回答

0

所以我假設你正在膨脹的片段,使用層次結構:

activity_main.xml中
的FrameLayout
--DrawerLayout
----包括app_bar_main
---- NavigationView

app_bar_main.xml:
Coordin atorLayout
--include content_main

content_main.xml:
RelativeLayout的
--FrameLayout (fragment_container)

+0

嗨,我如何修復上面的代碼? – user1060551

+0

你需要按照我的順序放置佈局,我還寫過其中的文件名 –

0

content_main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout 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" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:showIn="@layout/drawer_app_bar_dashboard"><FrameLayout 
    android:id="@+id/texeting_fram" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#ffffff" /></LinearLayout> 

你的java文件

setContentView(R.layout.activity_drawer_dashboard);//get tool bar for drawer navigation and hide main action bar 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar);//initial fragment 
    fragment = new Fragment_Main_Dashboard(); 
    android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); 
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
    fragmentTransaction.replace(R.id.texeting_fram, fragment); 
    fragmentTransaction.commit(); 
相關問題