2016-03-01 2 views
0

У меня возникают некоторые проблемы с некоторыми из моих XML-макетов, поскольку верхняя часть списка зарывается за моей панелью инструментов. Независимо от того, какие изменения я делаю, я не могу решить эту проблему.Android XML Top of List Off Cut

Я попытался поместить различные элементы в разные макеты, чтобы попытаться заставить его работать, но все равно ничего.

Может кто-нибудь объяснить мне, что я делаю неправильно?

XML

<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"> 
<!-- The main content view --> 

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/drawer_layout2"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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


    <ListView 
     android:id="@+id/favList" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/custom" 
     ></ListView> 

    <FrameLayout 
     android:id="@+id/container_body" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

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


<fragment 
    android:id="@+id/fragment_navigation_drawer" 
    android:name="com.example.rory.pocketchef.Fragments.FragmentDrawer" 
    android:layout_width="@dimen/nav_drawer_width" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:layout="@layout/fragment_navigation_drawer" 
    tools:layout="@layout/fragment_navigation_drawer" /> 

активность Вызов XML

public class Favourites extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener { 

private Toolbar mToolbar; 
private FragmentDrawer drawerFragment; 
DBMain db = new DBMain(this); 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_favourites); 

    mToolbar = (Toolbar) findViewById(R.id.toolbar); 

    setSupportActionBar(mToolbar); 
    getSupportActionBar().setDisplayShowHomeEnabled(true); 

    drawerFragment = (FragmentDrawer) getFragmentManager().findFragmentById(R.id.fragment_navigation_drawer); 
    drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar); 
    drawerFragment.setDrawerListener(this); 



    db.open(); 
    Cursor cursor = db.getAllFavItems(); 

    //String[] columns = new String[] {db.KEY_NAME, db.KEY_MEASUREMENT, db.KEY_ROWID}; 
    String[] columns = new String[] {db.KEY_RECIPE_NAME}; 

    int[] to = new int[] {R.id.recipeName}; 

    final SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(this,R.layout.possible_recipe_row, cursor, columns, to, 0); 

    ListView ingredientList = (ListView) findViewById(R.id.favList); 
    ingredientList.setAdapter(myCursorAdapter); 






} 

@Override 
public void onDrawerItemSelected(View view, int position) { 
    switch (position) { 
     case 0: 
      Intent intent= new Intent(Favourites.this,MainActivity.class); 
      startActivity(intent); 
      break; 
     case 1: 
      Intent intent2= new Intent(Favourites.this,Favourites.class); 
      startActivity(intent2); 
      break; 
     case 2: 
      Intent intent3= new Intent(Favourites.this,Contents.class); 
      startActivity(intent3); 
      break; 
     case 3: 
      Intent intent5 = new Intent(Favourites.this, Scanner.class); 
      startActivity(intent5); 
      break; 
     case 4: 
      SessionManager session1 = new SessionManager(this); 
      session1.setLogin(false); 

      SQLiteHandler handler = new SQLiteHandler(this); 
      handler.deleteUsers(); 

      Intent intent4 = new Intent(Favourites.this, LoginActivity.class); 
      startActivity(intent4); 
      finish(); 
      break; 

     default: 
      break; 
    } 
} 
} 
+0

Размер '' '' '' '' '' '' '' чтобы соответствовать родительскому, измените это или дайте ему 'margin_top =? Attr/actionbarSize' – drWisdom

+0

@drWisdom спасибо за предложение, которое оно сейчас работает – JJSmith

ответ

2

Вы можете установить marginTop="?android:attr/actionBarSize" в вашем ListView, так что список будет начать ниже панели действий.

Goodluck!

+0

Проверьте это http://stackoverflow.com/ вопросы/12301510/how-to-get-the-actionbar-height –

+0

Отличное спасибо за предложение, которое оно сейчас работает – JJSmith

1

Дайте и удостоверьтесь в своем AppBarLayout. android:id="@+id/myAppBarLayout" затем установите свойство layout_below в ListView следующим образом: android:layout_below="@+id/myAppBarLayout". Это основное исправление, вы не определили «пользовательский» идентификатор в любом месте вашего кода.

+0

Спасибо за предложения работает сейчас, +1 – JJSmith