我正在开发一个Android应用程序,其中我有一副可刷卡的卡片,比如在tinder app和左抽屉。
事情是抽屉滑动动作阻止卡刷卡动作...如果我禁用抽屉...然后我可以再次刷卡。 我正在使用这两个库。
有什么想法吗?
dependencies {
compile'com.lorentzos.swipecards:library:1.0.8'
compile 'com.android.support:appcompat-v7:21.0.3'
}
在我的抽屉下面添加并轻扫动作。
private void createDrawer(Bundle savedInstanceState) {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
drawerLayoutt = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerLayoutt.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
String[] countries = new String[] {
"Logo",
"Random",
"Menu",
"Send"
};
// Array of integers points to images stored in /res/drawable-ldpi/
int[] flags = new int[]{
R.drawable.ic_launcher,
R.drawable.ic_iv_dice,
R.drawable.iv_menu_list,
R.drawable.ic_iv_send
};
List<HashMap<String,String>> aList = new ArrayList<HashMap<String,String>>();
for(int i=0;i<4;i++){
HashMap<String, String> hm = new HashMap<String,String>();
hm.put("txt", countries[i]);
hm.put("flag", Integer.toString(flags[i]) );
aList.add(hm);
}
String[] from = { "flag","txt" };
// Ids of views in listview_layout
int[] to = { R.id.flag,R.id.txt};
// Instantiating an adapter to store each items
// R.layout.listview_layout defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.drawer_list_item, from, to);
// Getting a reference to listview of main.xml layout file
ListView listView = ( ListView ) findViewById(R.id.left_drawer);
// Setting the adapter to the listView
listView.setAdapter(adapter);
listView.setOnItemClickListener(new DrawerItemClickListener());
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayoutt, toolbar, R.string.fuckherface, R.string.fuckherface);
drawerLayoutt.setDrawerListener(actionBarDrawerToggle);
// enable ActionBar app icon to behave as action to toggle nav drawer
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
if (savedInstanceState == null) {
// selectItem(0);
}
uiHelper = new UiLifecycleHelper(this, null);
uiHelper.onCreate(savedInstanceState);
}
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}
private void selectItem(int position) {
switch (position)
{
case 0:
break;
case 1:
break;
case 2:
Intent i = new Intent(MainActivity.this, card_list.class);
MainActivity.this.startActivity(i);
break;
case 3:
Intent j = new Intent(MainActivity.this, card_send.class);
MainActivity.this.startActivity(j);
break;
}
}
@Override
public void setTitle(CharSequence title) {
getSupportActionBar().setTitle(title);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
actionBarDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
actionBarDrawerToggle.onConfigurationChanged(newConfig);
}
private void swipeListener() {
ButterKnife.inject(this);
arrayAdapter = new ArrayAdapter<>(this, R.layout.item, R.id.helloText, al );
flingContainer.setAdapter(arrayAdapter);
flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {
@Override
public void removeFirstObjectInAdapter() {
al.remove(0);
al_id.remove(0);
arrayAdapter.notifyDataSetChanged();
}
@Override
public void onLeftCardExit(Object dataObject) {
makeToast(MainActivity.this, "Left!");
myPoz++;
prefs.edit().putString("lastPoz", myPoz + "");
}
@Override
public void onRightCardExit(Object dataObject) {
makeToast(MainActivity.this, "Right!");
myPoz++;
prefs.edit().putString("lastPoz", myPoz + "");
}
@Override
public void onAdapterAboutToEmpty(int itemsInAdapter) {
jumper += 10;
int i = 0;
if (i < (db.count()-10)) {
for (i = jumper; i < jumper + 10; i++) {
ArrayList<Object> al_small = db.getSingleFact(i);
al.add(al_small.get(3));
al_id.add(al_small.get(0));
}
}
else {
i=0;
onAdapterAboutToEmpty(db.count());
}
}
@Override
public void onScroll(float scrollProgressPercent) {
View view = flingContainer.getSelectedView();
try {
view.findViewById(R.id.item_swipe_right_indicator).setAlpha(scrollProgressPercent < 0 ? -scrollProgressPercent : 0);
view.findViewById(R.id.item_swipe_left_indicator).setAlpha(scrollProgressPercent > 0 ? scrollProgressPercent : 0);
}
catch (Exception ex) //FU, exception
{
}
}
});
flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() {
@Override
public void onItemClicked(int itemPosition, Object dataObject) {
makeToast(MainActivity.this, itemPosition+"");
}
});
}
static void makeToast(Context ctx, String s){
Toast.makeText(ctx, s, Toast.LENGTH_SHORT).show();
}