AndroidXML列表的最顶端被删除

AndroidXML列表的最顶端被删除,android,xml,Android,Xml,我的一些XML布局遇到了一些问题,因为列表的顶部被隐藏在工具栏的后面。无论我做什么改变,我似乎都无法解决这个问题 我试着把各种不同的元素放到不同的布局中,试图让它发挥作用,但还是一无所获 有人能解释一下我做错了什么吗 XML <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.c

我的一些XML布局遇到了一些问题,因为列表的顶部被隐藏在工具栏的后面。无论我做什么改变,我似乎都无法解决这个问题

我试着把各种不同的元素放到不同的布局中,试图让它发挥作用,但还是一无所获

有人能解释一下我做错了什么吗

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" />
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;
    }
}
}

您可以在listview中设置
marginTop=“?android:attr/actionBarSize”
,以便列表从操作栏下方开始


祝你好运

您可以在listview中设置
marginTop=“?android:attr/actionBarSize”
,以便列表从操作栏下方开始


祝你好运

为AppBarLayout提供名称和id
android:id=“@+id/myAppBarLayout”
然后在ListView中设置属性下方的布局,如下所示
android:layout=“@+id/myAppBarLayout”
。这是最基本的修复,您没有在代码中的任何地方定义“自定义”id

为AppBarLayout提供名称和id
android:id=“@+id/myAppBarLayout”
然后在ListView中设置属性下方的布局,如下所示
android:layout=“@+id/myAppBarLayout”
。这是最基本的修复,您没有在代码中的任何地方定义“自定义”id

您的
列表视图
高度设置为与父级匹配,请更改该设置或将其设置为
margin\u top=?attr/actionbarSize
@drwillist感谢您的建议,它现在正在工作您的
列表视图
高度设置为与父级匹配,要么改变它,要么给它一个
margin\u top=?attr/actionbarSize
@drwist谢谢你的建议它现在正在工作检查这个检查这个