2014-07-14 7 views
1

안녕하세요 저는 CoverFlow를 사용중인 앱을 만들고 있습니다. 하지만 나는 imageview와 함께 textview를 추가하고 싶다. 아래처럼 AbstractCoverFlowImageAdapter를 변경했습니다.Coverflow with android textview with

/** 
* This class is an adapter that provides base, abstract class for images 
* adapter. 
* 
*/ 
public abstract class AbstractCoverFlowImageAdapter extends BaseAdapter { 

    /** The Constant TAG. */ 
    private static final String TAG = AbstractCoverFlowImageAdapter.class.getSimpleName(); 

    /** The width. */ 
    private float width = 0; 

    /** The height. */ 
    private float height = 0; 

    /** The bitmap map. */ 
    private final Map<Integer, WeakReference<Bitmap>> bitmapMap = new HashMap<Integer, WeakReference<Bitmap>>(); 

    public AbstractCoverFlowImageAdapter() { 
     super(); 
    } 

    /** 
    * Set width for all pictures. 
    * 
    * @param width 
    *   picture height 
    */ 
    public synchronized void setWidth(final float width) { 
     this.width = width; 
    } 

    /** 
    * Set height for all pictures. 
    * 
    * @param height 
    *   picture height 
    */ 
    public synchronized void setHeight(final float height) { 
     this.height = height; 
    } 

    @Override 
    public final Bitmap getItem(final int position) { 
     final WeakReference<Bitmap> weakBitmapReference = bitmapMap.get(position); 
     if (weakBitmapReference != null) { 
      final Bitmap bitmap = weakBitmapReference.get(); 
      if (bitmap == null) { 
       Log.v(TAG, "Empty bitmap reference at position: " + position + ":" + this); 
      } else { 
       Log.v(TAG, "Reusing bitmap item at position: " + position + ":" + this); 
       return bitmap; 
      } 
     } 
     Log.v(TAG, "Creating item at position: " + position + ":" + this); 
     final Bitmap bitmap = createBitmap(position); 
     bitmapMap.put(position, new WeakReference<Bitmap>(bitmap)); 
     Log.v(TAG, "Created item at position: " + position + ":" + this); 
     return bitmap; 
    } 

    /** 
    * Creates new bitmap for the position specified. 
    * 
    * @param position 
    *   position 
    * @return Bitmap created 
    */ 
    protected abstract Bitmap createBitmap(int position); 

    /* 
    * (non-Javadoc) 
    * 
    * @see android.widget.Adapter#getItemId(int) 
    */ 
    @Override 
    public final synchronized long getItemId(final int position) { 
     return position; 
    } 

    /* 
    * (non-Javadoc) 
    * 
    * @see android.widget.Adapter#getView(int, android.view.View, 
    * android.view.ViewGroup) 
    */ 


    public final synchronized View getView(final int position, final View convertView, final ViewGroup parent) { 
     // ImageView imageView; 
     View root; 
     if (convertView == null) { 
      final Context context = parent.getContext(); 
      LayoutInflater mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      root = mInflater.inflate(R.layout.coverflowitem, null); 
      root.setLayoutParams(new CoverFlow.LayoutParams(150, 150)); 
     } else { 
      Log.v(TAG, "Reusing view at position: " + position + ":" + this); 
      root = convertView; 
     } 
     ImageView imageView = (ImageView)root.findViewById(R.id.coverflow_image); 
     TextView text = (TextView)root.findViewById(R.id.descriptionText); 
     imageView.setImageBitmap(getItem(position)); 
     text.setText("You Win!"); 

     return root; 
    } 

} 

getView() 메소드의 반환 유형을 ImageView에서보기로 변경했습니다.

그리고 내 커버 플로우의 XML 및 커버 플로우 항목 XML입니다 타격 각각

coverflow.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/women3"> 

    <com.android.jigsawpuzzle.puzzle.coverflow.CoverFlow 
     xmlns:coverflow="http://schemas.android.com/apk/res-auto/org.worldsproject.puzzle" 
     android:id="@+id/coverflow" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dip" 
     coverflow:imageHeight="250dip" 
     coverflow:imageReflectionRatio="0.2" 
     coverflow:imageWidth="250dip" 
     coverflow:reflectionGap="2dip" 
     coverflow:withReflection="true" /> 

    <Button 
     android:id="@+id/difficulty" 
     android:layout_width="80dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerInParent="true" 
     android:text="@string/easy" 
     android:layout_marginBottom="10dp" 
     android:background="@drawable/profile_border"/> 

</RelativeLayout> 

coverflowitems.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <ImageView android:id="@+id/coverflow_image" 
       android:layout_width="100dp" 
       android:layout_height="100dp" 
       android:layout_gravity="center" 
       android:contentDescription="image"/> 

    <ScrollView android:id="@+id/sv" 
       android:layout_width="250dp" 
       android:layout_height="150dp" 
       android:background="@drawable/profile_border" 
       android:layout_gravity="center_horizontal"> 

     <TextView android:id="@+id/descriptionText" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="left" 
        android:textColor="@color/black" 
        android:text="Image description"/> 

    </ScrollView> 


</LinearLayout> 

이제 내 문제는 내가 오류 동안 얻고 있다는 것입니다 앱 실행 : -

07-14 12:43:03.089: E/AndroidRuntime(9976): FATAL EXCEPTION: main 
07-14 12:43:03.089: E/AndroidRuntime(9976): java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.ImageView 
07-14 12:43:03.089: E/AndroidRuntime(9976):  at CoverFlow.getChildStaticTransformation(CoverFlow.java:288) 

이 오류를 제거하고 작업 코드로 리디렉션하는 데 도움을주십시오.

미리 감사드립니다.

답변

0

내가 잠시 다시이 문제가 건너와 해결책을 발견했습니다 여기를보세요. 내 대답을 게시했습니다 :

Coverflow with custom adapter