简体   繁体   中英

Android XML Top of List Being Cut Off

I am having some trouble with some of my XML layouts in that the top of the list is being buried behind the back of my tool bar. No matter what changes I make I cannot seem to fix this problem.

I have tried putting various different elements into different layouts to try make it work but still nothing.

Can some one explain to me what I am doing wrong?

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

Activity Calling 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;
    }
}
}

You can set marginTop="?android:attr/actionBarSize" in your listview so that list will start below action bar.

Goodluck!

Give and id to your AppBarLayout. android:id="@+id/myAppBarLayout" then set layout_below property in ListView like this android:layout_below="@+id/myAppBarLayout" . This is the basic fix, You haven't defined "custom" id any where in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM