我从解析数据库下载图片和名称并创建一个cardstack。每个视图都有一个名称和一张图片,但是我没有看到我的视图的第一张图片(位置0),直到我使用向左滑动或向右滑动按钮(然后我看到它擦掉),nameAgeLabel工作正常。 / p>
您有什么想法我可以解决它吗?没有什么应该重叠它,我一次又一次地检查,但也许我忽略了关于我的适配器中的位置0的一些特殊情况。数据也应该没问题,否则nameAgeLabel将无效。
我可以删除content.xml中的一些布局,但这也无济于事。
编辑:我现在只在我的日志中获取第一个视图的信息:
W/View: requestLayout()
improperly called by android.support.v7.widget.AppCompatTextView....app:id/nameAgeLabel} during
layout: running second layout pass
SwipeDeckAdapter:
public class SwipeDeckAdapter extends BaseAdapter {
private LinkedList<String> data;
private Context context;
private LinkedList<String> userIds;
private Hashtable<String,String> userNames;
private Hashtable<String,String> userHashtags;
private Hashtable<String,Bitmap> userImages;
private Hashtable<String,ArrayList<String>> userAccepted;
private TextView nameAgeLabel;
public SwipeDeckAdapter(LinkedList<String> data, Context context, LinkedList<String> userIds, Hashtable<String,String> userNames, Hashtable<String,String> userHashtags, Hashtable<String,Bitmap> userImages, Hashtable<String,ArrayList<String>> userAccepted, TextView nameAgeLabel) {
this.data = data;
this.context = context;
this.userIds = userIds;
this.userNames = userNames;
this.userHashtags = userHashtags;
this.userImages = userImages;
this.userAccepted = userAccepted;
this.nameAgeLabel = nameAgeLabel;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View View, ViewGroup parent) {
Log.d("position:", String.valueOf(position));
Log.d("laenge user id", String.valueOf(userIds.size()));
final String currentUserId = userIds.get(position);
View v = View;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.content_single_mode_vc, parent, false);
}
ImageView imageView = (ImageView) v.findViewById(R.id.offer_image);
Bitmap image;
try {
image = userImages.get(currentUserId);
imageView.setImageBitmap(image);
} catch (IOError error) {
error.printStackTrace();
}
Log.d("info", userNames.toString());
Log.d("info", userNames.get(currentUserId));
nameAgeLabel.setText(userNames.get(userIds.get(position)));
return v;
}
我在另一个类中调用它:
//next line in my onCreate
cardStack = (SwipeDeck) findViewById(R.id.swipe_deck);
//back in my method
adapter= new SwipeDeckAdapter(data, getApplicationContext(), userIds, userNames, userHashtags, userImages, userAccepted,nameAgeLabel);
// e.printStackTrace();
if(cardStack != null){
cardStack.setAdapter(adapter);
}
content_single_mode_vc.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="8dp"
card_view:cardElevation="8dp"
card_view:cardUseCompatPadding="true"
android:layout_margin="8dp"
android:gravity="center_horizontal"
android:padding="25dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/offer_image"
android:layout_width="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
android:layout_height="200dp" />
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
activity_single_mode_vc.xml
<?xml version="1.0" encoding="utf-8"?>
<com.daprlabs.aaron.swipedeck.layouts.SwipeFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:swipedeck="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipeLayout"
android:orientation="vertical"
android:background="@color/white">
<com.daprlabs.aaron.swipedeck.SwipeDeck
android:id="@+id/swipe_deck"
android:layout_width="match_parent"
android:layout_height="700dp"
android:padding="20dp"
android:layout_marginTop="60dp"
swipedeck:max_visible="1"
swipedeck:card_spacing="15dp"
swipedeck:swipe_enabled="true"
swipedeck:render_above="true">
</com.daprlabs.aaron.swipedeck.SwipeDeck>
<Button
android:id="@+id/close"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="50dp"
android:layout_marginLeft="20dp"
android:layout_gravity="bottom"
android:elevation="1dp"
android:background="@drawable/close"
android:backgroundTint="@color/light" />
<Button
android:id="@+id/check"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="50dp"
android:layout_marginRight="20dp"
android:layout_gravity="bottom|right"
android:background="@drawable/check"
android:backgroundTint="@color/light" />
<TextView
android:layout_width="wrap_content"
android:padding="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="wrap_content"
android:layout_marginTop="350dp"
android:id="@+id/nameAgeLabel"
android:background="@color/separator"
/>
</com.daprlabs.aaron.swipedeck.layouts.SwipeFrameLayout>
答案 0 :(得分:0)
您正在使用swipedeck:max_visible =&#34; 1&#34;在DeckSwipe的布局中,这就是为什么它是库中的错误。尝试将max_visible增加到2或3,它将适合您。
如果您只需要显示一张卡,您可以修改库中的SwipeDeck.java并替换setAdapter函数,如下所示:
public void setAdapter(final Adapter adapter)
{
if (adapter == null)
return;
if (this.mAdapter != null) {
this.mAdapter.unregisterDataSetObserver(observer);
}
mHasStableIds = adapter.hasStableIds();
mAdapter = adapter;
.
.
.
adapter.registerDataSetObserver(observer);
if (deck.size() > 0)
addNextView();
removeAllViewsInLayout();
requestLayout();
}