Java 布局不';不显示视图的第一项

Java 布局不';不显示视图的第一项,java,android,xml,view,swipe,Java,Android,Xml,View,Swipe,我从parse数据库下载图片和名称,并创建一个cardstack。每个视图都有一个名称和一张图片,但我看不到视图的第一张图片(位置0),直到我使用向左滑动或向右滑动按钮(然后我看到它向外滑动),nameAgeLabel工作正常 你有什么主意我怎么修吗?没有什么应该重叠它,我一次又一次地检查,但可能我忽略了关于适配器中位置0的一些特殊内容。数据也应该是良好的,否则nameAgeLabel将无法工作 我可以删除content.xml中的一些布局,但这也没用 编辑:我现在只在日志中获取第一次查看的信息

我从parse数据库下载图片和名称,并创建一个cardstack。每个视图都有一个名称和一张图片,但我看不到视图的第一张图片(位置0),直到我使用向左滑动或向右滑动按钮(然后我看到它向外滑动),nameAgeLabel工作正常

你有什么主意我怎么修吗?没有什么应该重叠它,我一次又一次地检查,但可能我忽略了关于适配器中位置0的一些特殊内容。数据也应该是良好的,否则nameAgeLabel将无法工作

我可以删除content.xml中的一些布局,但这也没用

编辑:我现在只在日志中获取第一次查看的信息:

W/View: requestLayout() 
improperly called by android.support.v7.widget.AppCompatTextView....app:id/nameAgeLabel} during 
layout: running second layout pass
SwipedCKAdapter:

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;
}
content\u single\u mode\u 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>

活动\u单一\u模式\u 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>

您在DeckSwipe的布局中使用swipedeck:max_visible=“1”,这就是为什么它是库中的一个bug。尝试将可见的最大值增加到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();
    }
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();
    }