我的一些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" />
活动调用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 :(得分:2)
您可以在列表视图中设置marginTop="?android:attr/actionBarSize"
,以便列表将从操作栏下方开始。
古德勒克!
答案 1 :(得分:1)
给你的AppBarLayout提供ID。 android:id="@+id/myAppBarLayout"
然后在ListView中设置layout_below属性,如android:layout_below="@+id/myAppBarLayout"
。这是基本修复,你还没有定义&#34; custom&#34; id代码中的任何位置。