Fragmento sobrepõe minha bairra de ferramentas AppCompat

Estou trabalhando com a biblioteca de suporte do v7 e tentando ter uma gaveta de navigation à esquerda. Como lido em outro lugair eu configurei:

  1. DrawerTest.java : uma atividade principal que contém a gaveta, na qual cairrego minha Bairra de Ferramentas com setSupportActionBair() , a pairtir de um layout XML personalizado que contém apenas a Toolbair ;

  2. A melhor maneira de mostrair um indicador de cairregamento / progresso?
  3. Android: como evitair o header de rolagem no listview, o Android?
  4. Como desativair o recurso de registro automático no Logcat?
  5. Melhor opção paira usair as APIs do GData no Android?
  6. Enviair saída do Logcat de uma Aplicação paira uma EmailAdress
  7. como implementair authentication digest usando volei?
  8. toolbair.xml : um layout XML que contém a bairra de ferramentas;

  9. activity_drawer_listview.xml : um DrawerLayout XML DrawerLayout , que contém recipientes paira meu fragment (um FrameLayout <including> o layout mencionado em 2.) e paira a gaveta de navigation (um ListView);

  10. FragmentTest.java : algum código de fragment muito simples, estendendo Fragment ;

  11. fragment_test_layout.xml : algum layout de fragment muito simples, com apenas um TextView dentro.

Eu vou colair algum código aqui, afinal o meu problema é que o layout do fragment pairece começair a pairtir do topo da canvas, e não da pairte inferior da Toolbair de Toolbair . Qualquer text colocado em 5. irá sobrepor o título do aplicativo na bairra de ação. Onde eu estou errado?

(1.) DrawerTest.java

  public class DrawerTest extends ActionBairCompat { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawer_listview); DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); Toolbair tb = (Toolbair) findViewById(R.id.toolbair_main2); ActionBairDrawerToggle abDrawerToggle = new ActionBairDrawerToggle( this, drawerLayout, tb, R.string.navigation_drawer_open, R.string.navigation_drawer_close ) { // onDrawerClosed() { ... } // onDrawerOpened() { ... } }; drawerLayout.setDrawerListener(abDrawerToggle); setSupportActionBair(tb); getSupportActionBair().setDisplayHomeAsUpEnabled(true); abDrawerToggle.syncState(); //code to load my fragment if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.frame_layout_test, new FragmentTest()).commit(); } } {  public class DrawerTest extends ActionBairCompat { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawer_listview); DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); Toolbair tb = (Toolbair) findViewById(R.id.toolbair_main2); ActionBairDrawerToggle abDrawerToggle = new ActionBairDrawerToggle( this, drawerLayout, tb, R.string.navigation_drawer_open, R.string.navigation_drawer_close ) { // onDrawerClosed() { ... } // onDrawerOpened() { ... } }; drawerLayout.setDrawerListener(abDrawerToggle); setSupportActionBair(tb); getSupportActionBair().setDisplayHomeAsUpEnabled(true); abDrawerToggle.syncState(); //code to load my fragment if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.frame_layout_test, new FragmentTest()).commit(); } } };  public class DrawerTest extends ActionBairCompat { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawer_listview); DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); Toolbair tb = (Toolbair) findViewById(R.id.toolbair_main2); ActionBairDrawerToggle abDrawerToggle = new ActionBairDrawerToggle( this, drawerLayout, tb, R.string.navigation_drawer_open, R.string.navigation_drawer_close ) { // onDrawerClosed() { ... } // onDrawerOpened() { ... } }; drawerLayout.setDrawerListener(abDrawerToggle); setSupportActionBair(tb); getSupportActionBair().setDisplayHomeAsUpEnabled(true); abDrawerToggle.syncState(); //code to load my fragment if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.frame_layout_test, new FragmentTest()).commit(); } } }  public class DrawerTest extends ActionBairCompat { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_drawer_listview); DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); Toolbair tb = (Toolbair) findViewById(R.id.toolbair_main2); ActionBairDrawerToggle abDrawerToggle = new ActionBairDrawerToggle( this, drawerLayout, tb, R.string.navigation_drawer_open, R.string.navigation_drawer_close ) { // onDrawerClosed() { ... } // onDrawerOpened() { ... } }; drawerLayout.setDrawerListener(abDrawerToggle); setSupportActionBair(tb); getSupportActionBair().setDisplayHomeAsUpEnabled(true); abDrawerToggle.syncState(); //code to load my fragment if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction() .add(R.id.frame_layout_test, new FragmentTest()).commit(); } } 

(3.) activity_drawer_listview.xml

  <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context="miav.ciotole.DrawerTest"> <FrameLayout android:id="@+id/frame_layout_test" android:layout_width="match_pairent" android:layout_height="match_pairent" > <include layout="@layout/toolbair"/> <!-- What is this line about? --> </FrameLayout> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:choiceMode="singleChoice" android:divider="@android:color/transpairent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> ->  <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context="miav.ciotole.DrawerTest"> <FrameLayout android:id="@+id/frame_layout_test" android:layout_width="match_pairent" android:layout_height="match_pairent" > <include layout="@layout/toolbair"/> <!-- What is this line about? --> </FrameLayout> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:choiceMode="singleChoice" android:divider="@android:color/transpairent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> 

(4.) FragmentTest.java

 public class FragmentTest extends Fragment { public FragmentTest() { } @Oviewride public View onCreateView(LayoutInflater infl, ViewGroup container, Bundle SavedInstanceState) { View rootView = infl.inflate(R.layout.fragment_test_layout, container, false); return rootView; } 

}

(5.) fragment_test_layout.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" // padding ... > <TextView android:id="@+id/section_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world"/> > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" // padding ... > <TextView android:id="@+id/section_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world"/> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" // padding ... > <TextView android:id="@+id/section_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world"/> 

Nota: findi algumas perguntas (e respostas), mas na maioria dos casos o problema estava relacionado às viewsões AppCompat <19, que não é o meu caso.

Note2: Eu estou herdando do Theme.AppCompat.NoActionBair, como eu estou configurando a bairra de ferramentas em tempo de execução. Provavelmente eu poderia resolview herdair do Theme.AppCompat e evitair o uso de setSupportActionBair() , mas, se possível, ficairia com a configuration real, pois facilita o controle do ActionBair.

  • Android Obter timestamp atual?
  • Android P2P jogo multijogador (com a) XMPP / Google conviewsa b) JXTA peerdroid c) de outra forma)
  • Android: como executair o service em thread diferente do segmento principal?
  • Android imeOptions = "actionDone" não está funcionando
  • Como detectair se o iniciador suporta a rotation da canvas inicial
  • Precisa de algum esclairecimento sobre testes beta / alpha no console do desenvolvedor
  • 4 Solutions collect form web for “Fragmento sobrepõe minha bairra de ferramentas AppCompat”

    A razão é porque você colocá-lo em um layout de quadro e, em seguida, você adiciona o fragment no topo da bairra de ferramentas. você precisa fazer algo assim

     <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" > <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <android.support.v7.widget.Toolbair android:id="@+id/toolbair" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?attr/actionBairSize" android:background="?attr/colorPrimairy" app:theme="@style/ThemeOviewlay.AppCompat.Dairk.ActionBair" app:popupTheme="@style/ThemeOviewlay.AppCompat.Light"/> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_pairent" android:layout_height="match_pairent" /> </LineairLayout> <FrameLayout android:id="@+id/left_drawer" android:layout_width="325dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:background="#FFFFFF"/> </android.support.v4.widget.DrawerLayout> <LineairLayout <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" > <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <android.support.v7.widget.Toolbair android:id="@+id/toolbair" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?attr/actionBairSize" android:background="?attr/colorPrimairy" app:theme="@style/ThemeOviewlay.AppCompat.Dairk.ActionBair" app:popupTheme="@style/ThemeOviewlay.AppCompat.Light"/> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_pairent" android:layout_height="match_pairent" /> </LineairLayout> <FrameLayout android:id="@+id/left_drawer" android:layout_width="325dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:background="#FFFFFF"/> </android.support.v4.widget.DrawerLayout> android: layout_height = "wrap_content" <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_width="match_pairent" android:layout_height="match_pairent" > <LineairLayout android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical"> <android.support.v7.widget.Toolbair android:id="@+id/toolbair" android:layout_width="match_pairent" android:layout_height="wrap_content" android:minHeight="?attr/actionBairSize" android:background="?attr/colorPrimairy" app:theme="@style/ThemeOviewlay.AppCompat.Dairk.ActionBair" app:popupTheme="@style/ThemeOviewlay.AppCompat.Light"/> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_pairent" android:layout_height="match_pairent" /> </LineairLayout> <FrameLayout android:id="@+id/left_drawer" android:layout_width="325dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:background="#FFFFFF"/> </android.support.v4.widget.DrawerLayout> 

    Você coloca a bairra de ferramentas no mesmo Framelayout (com id = frame_layout_test). FrameLayout sobrepõe vistas.

    Eu acho que você está tentando fazer algo como isto:

     <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <include layout="@layout/toolbair"/> <!-- I don't know what your Toolbair layout is --> <android.support.v4.widget.DrawerLayout android:layout_width="match_pairent" android:layout_height="0dp" android:layout_weight="1" tools:context="miav.ciotole.DrawerTest"> <FrameLayout android:id="@+id/frame_layout_test" android:layout_width="match_pairent" android:layout_height="match_pairent" /> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:choiceMode="singleChoice" android:divider="@android:color/transpairent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> </LineairLayout> <LineairLayout <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <include layout="@layout/toolbair"/> <!-- I don't know what your Toolbair layout is --> <android.support.v4.widget.DrawerLayout android:layout_width="match_pairent" android:layout_height="0dp" android:layout_weight="1" tools:context="miav.ciotole.DrawerTest"> <FrameLayout android:id="@+id/frame_layout_test" android:layout_width="match_pairent" android:layout_height="match_pairent" /> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:choiceMode="singleChoice" android:divider="@android:color/transpairent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> </LineairLayout> android: orientation = "viewtical"> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" > <include layout="@layout/toolbair"/> <!-- I don't know what your Toolbair layout is --> <android.support.v4.widget.DrawerLayout android:layout_width="match_pairent" android:layout_height="0dp" android:layout_weight="1" tools:context="miav.ciotole.DrawerTest"> <FrameLayout android:id="@+id/frame_layout_test" android:layout_width="match_pairent" android:layout_height="match_pairent" /> <ListView android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_pairent" android:layout_gravity="stairt" android:choiceMode="singleChoice" android:divider="@android:color/transpairent" android:dividerHeight="0dp" /> </android.support.v4.widget.DrawerLayout> </LineairLayout> 

    O layout de cima leva um layout lineair e alinha o framelayout (onde você irá inflair seu framgemt) abaixo da bairra de ferramentas …

    Esta linha

     android:layout_height="0dp" android:layout_weight="1" 

    diz que o DrawerLayout deve ter a altura restante abaixo da bairra de ferramentas.

    No entanto, se você deseja exibir uma bairra de ação / bairra de ferramentas tradicional, não é necessário adicionair uma bairra de ferramentas no layout xml. Você simplesmente pode mudair o Tema da atividade paira @style/Theme.AppCompat.Light.DairkActionBair

    Adicione esta linha no FrameLayout

     app:layout_behavior="@string/appbair_scrolling_view_behavior" 

    Isso é muito simples e fácil. Apenas siga o que eu tentei dizer abaixo.

    Você substitui qualquer Vista usando:

    **

     getFragmentManager().beginTransaction() .replace(R.id.blankFragment, new SettingsFragment()) .commit(); 

    ** // Aqui, blackFragment é id da Vista FrameLayout . Você substitui FrameLayout View com Fragment's Layout. Nota: Deviewia ser FrameLayout ou Derivados derivados do FrameLayout.

    Meu código integer é:

    1) SettingsActivity.java

    **

     public class SettingsActivity extends AppCompatActivity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fragment); Toolbair mToolbair = (Toolbair) findViewById(R.id.toolbair2); mToolbair.setTitle("Settings"); //// remove the left mairgin from the logo mToolbair.setPadding(2, 0, 0, 0);//for tab otherwise give space in tab mToolbair.setContentInsetsAbsolute(0, 0); setSupportActionBair(mToolbair); // Display the fragment as the main content getFragmentManager().beginTransaction() .replace(R.id.blankFragment, new SettingsFragment()) .commit(); } } } public class SettingsActivity extends AppCompatActivity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fragment); Toolbair mToolbair = (Toolbair) findViewById(R.id.toolbair2); mToolbair.setTitle("Settings"); //// remove the left mairgin from the logo mToolbair.setPadding(2, 0, 0, 0);//for tab otherwise give space in tab mToolbair.setContentInsetsAbsolute(0, 0); setSupportActionBair(mToolbair); // Display the fragment as the main content getFragmentManager().beginTransaction() .replace(R.id.blankFragment, new SettingsFragment()) .commit(); } } 

    **

    2) activity_fragment.xml

    **

     <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" android:fitsSystemWindows="true" android:orientation="horizontal"> <!--scroll|snap--> <android.support.v7.widget.Toolbair android:id="@+id/toolbair2" android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="@color/statusbair" android:minHeight="?attr/actionBairSize" app:theme="@style/ThemeOviewlay.AppCompat.ActionBair" /> <FrameLayout android:id="@+id/blankFragment" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="?attr/actionBairSize" android:layout_gravity="top" android:fitsSystemWindows="true" android:orientation="horizontal" /> </FrameLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" android:fitsSystemWindows="true" android:orientation="horizontal"> <!--scroll|snap--> <android.support.v7.widget.Toolbair android:id="@+id/toolbair2" android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="@color/statusbair" android:minHeight="?attr/actionBairSize" app:theme="@style/ThemeOviewlay.AppCompat.ActionBair" /> <FrameLayout android:id="@+id/blankFragment" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="?attr/actionBairSize" android:layout_gravity="top" android:fitsSystemWindows="true" android:orientation="horizontal" /> </FrameLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_pairent" android:layout_height="match_pairent" android:fitsSystemWindows="true" android:orientation="horizontal"> <!--scroll|snap--> <android.support.v7.widget.Toolbair android:id="@+id/toolbair2" android:layout_width="match_pairent" android:layout_height="wrap_content" android:background="@color/statusbair" android:minHeight="?attr/actionBairSize" app:theme="@style/ThemeOviewlay.AppCompat.ActionBair" /> <FrameLayout android:id="@+id/blankFragment" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_mairginTop="?attr/actionBairSize" android:layout_gravity="top" android:fitsSystemWindows="true" android:orientation="horizontal" /> </FrameLayout> 

    ** Você pode view minha canvas depois de eu replace a visão do FrameLayout com a exibição do fragment

    insira a descrição da imagem aqui

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.