2017-05-19 11 views
0

パーズデータベースから画像と名前をダウンロードし、カードスタックを作成します。すべてのビューには名前と画像がありますが、スワイプの左端またはスワイプの右端のボタン(次にスワイプして見える)が表示されるまで、私のビュー(位置0)の最初の画像は表示されません。レイアウトの最初のアイテムが表示されない

私はどのように修正することができますか?それを重ねる必要はありません。何度も何度もチェックしましたが、アダプターの位置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:

//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); 
          } 

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_single_mode_vc.xml:

それは、ライブラリのバグである理由ですDeckSwipeのレイアウトにmax_visible = "1":あなたはswipedeckを使用している
<?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

。 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(); 
    } 
関連する問題