我有一個活動,顯示一個AppToolbar
旁邊RecyclerView
它位於Toolbar
下面。 RecyclerView
的每一行都是CardView
。我的問題是RecyclerView
根本不滾動。它似乎沒有收到任何手勢回調。Android回收站視圖不滾動
這是我的主要佈局的xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="@color/colorActivityBackground"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rv"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="vertical"
android:fadeScrollbars="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<include layout="@layout/tool_bar" />
<include layout="@layout/nav_drawer_layout" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_add"
app:layout_anchor="@id/rv"
app:layout_anchorGravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
編輯:下面是工具欄代碼:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="false"
android:theme="@style/AppTheme.AppBarOverlay"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
android:theme="@style/AppTheme.AppBarOverlay"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
這裏也是我的資產淨值抽屜佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize">
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- The navigation drawer -->
<android.support.v7.widget.RecyclerView
android:id="@+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#99ccff" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
而且這裏是我的主要活動,我填充我的回收商視圖:
package bikurim.silverfix.com.bikurim;
import android.app.SearchManager;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import java.util.ArrayList;
import bikurim.silverfix.com.bikurim.adapters.MenuDrawerAdapter;
import bikurim.silverfix.com.bikurim.adapters.RecyclerViewAdapter;
import bikurim.silverfix.com.bikurim.items.FamilyItem;
public class MainActivity extends AppCompatActivity {
private ArrayList<FamilyItem> families = new ArrayList<FamilyItem>();
private ArrayList<bikurim.silverfix.com.bikurim.items.MenuItem> items = new ArrayList<bikurim.silverfix.com.bikurim.items.MenuItem>();
private DrawerLayout drawerLayout;
private ActionBarDrawerToggle drawerToggle;
private RecyclerView recyclerView, menuView;
private RecyclerViewAdapter adapter;
private MenuDrawerAdapter navAdapter;
private SearchView searchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_families);
// Setting up the tool bar
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// Setting up the main lists and their adapters
fillList();
createMenuItems();
recyclerView = (RecyclerView) findViewById(R.id.rv);
menuView = (RecyclerView) findViewById(R.id.right_drawer);
adapter = new RecyclerViewAdapter(families);
navAdapter = new MenuDrawerAdapter(items);
// Default Animator
DefaultItemAnimator animator = new DefaultItemAnimator();
recyclerView.setItemAnimator(animator);
menuView.setItemAnimator(animator);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
menuView.setLayoutManager(new LinearLayoutManager(this));
menuView.setAdapter(navAdapter);
Log.d("Menu Items Count:", ""+navAdapter.getItemCount());
// Setting up the navigation drawer side-menu with DrawerLayout
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer is in closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
getSupportActionBar().setTitle(R.string.app_name);
}
/** Called when a drawer is in open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle(R.string.drawer_name);
}
};
drawerLayout.addDrawerListener(drawerToggle);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Does absolutly nothing, yet!", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
private void fillList() {
families.add(new FamilyItem("Ohayon", "12:36"));
families.add(new FamilyItem("Zohar", "14:23"));
families.add(new FamilyItem("Lasry", "15:55"));
families.add(new FamilyItem("Zambuzak", "17:45"));
families.add(new FamilyItem("Cohen", "11:33"));
families.add(new FamilyItem("Tapera", "09:25"));
families.add(new FamilyItem("Ochuya", "09:25"));
families.add(new FamilyItem("Konichiwua", "09:25"));
families.add(new FamilyItem("Kontaktiwa", "09:25"));
}
private void createMenuItems() {
items.add(new bikurim.silverfix.com.bikurim.items.MenuItem(R.drawable.about, "עזרה"));
items.add(new bikurim.silverfix.com.bikurim.items.MenuItem(R.drawable.settings, "הגדרות"));
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
drawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_families, menu);
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
adapter.getFilter().filter(query);
return true; // handled
}
@Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
return true;
}
});
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
//noinspection SimplifiableIfStatement
if (id == R.id.action_search) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
從您發佈的內容看,它們看起來都應該起作用。發佈tool_bar,nav_drawer_layout以及用於填充回收站視圖的代碼。 –
我在帖子後面添加了這些代碼 –
你在那裏有很多事情要做。我對DrawerLayout並不是很熟悉,但我不認爲你是按照預期使用它的,我很困惑你爲什麼有2個recyclerviews。查看協調員,AppBar和抽屜佈局應該如何交互的答案:http://stackoverflow.com/a/33413334/1224186 –