I am trying to open the Android sample project - Navigation Drawer in Android Studio, but got error while building it.
These are the steps to reproduce it:
Error:(43) No resource identifier found for attribute 'layoutManager' in package 'com.example.android.navigationdrawer'
Android Studio version is - 1.4 Beta 4
Thanks in advance for any help.
You can certainly still define LayoutManagers and more via xml. Here's an example using the native GridLayoutManager:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/posters_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="vertical"
app:layoutManager="android.support.v7.widget.GridLayoutManager"
app:reverseLayout="false"
app:spanCount="3"
app:stackFromEnd="false" />
If you want to use a custom LayoutManager follow the rules defined here:
R.attr.html#layoutManager
The compiler cannot find this attribute in the activity_navigation_drawer.xml
:
app:layoutManager="LinearLayoutManager"
To fix this
Remove this attribute from the XML so your Recyclerview looks like this:
<android.support.v7.widget.RecyclerView
android:id="@+id/left_drawer"
android:scrollbars="vertical"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left|start"
android:choiceMode="singleChoice"
android:divider="@null"/>
press the Gradle Sync button
In NavigationDrawerActivity
, add the following 2 lines of code in your OnCreate();
LinearLayoutManager mLinearLayoutmanager = new LinearLayoutManager(this);
mDrawerList.setLayoutManager(mLinearLayoutmanager);
So your code now looks like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_navigation_drawer);
mTitle = mDrawerTitle = getTitle();
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (RecyclerView) findViewById(R.id.left_drawer);
LinearLayoutManager mLinearLayoutmanager = new LinearLayoutManager(this);
mDrawerList.setLayoutManager(mLinearLayoutmanager);
....
Good luck
Edit:
The reason why this the original xml code is no longer working, is most likely that the xmlns:app="http://schemas.android.com/apk/res-auto"
namespace is no longer supporting the layoutManager
attribute.
More info on the namespace can be found here: https://stackoverflow.com/a/26692768/3708094
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With