2012-12-04 2 views
2
안드로이드

에서 XML 레이아웃에 크고 아무런 문제이 커버 플로우, 나는이 웹 사이트에서 커버 플로우에 대한 몇 가지 코드를 사용하고

normal working coverflow

http://www.inter-fuser.com/2010/01/android-coverflow-widget.html을 작품 표시되지 커버 플로우. 그러나 내가 그것을 보여주지 않을 xml 레이아웃 안에 넣으려고 할 때, coverflow에 대한 검은 색 배경 화면 만 나타나지만 coverfow가 없습니다. 내가 XML 레이아웃의 내부에 넣어 싶 었

missing coverflow in layout

이유 때문에 페이지 하단에 버튼을 넣어 필요하다. 그래서 Coverflow 아래 화면 하단에 버튼이있는 xml 레이아웃을 만들기로 결정했습니다.

무엇이 잘못되었거나 커버 플로우가 XML 레이아웃 내부에서 작동하지 않는 것은 무엇입니까?

아마이 코드가 작동하지 않을 수도 있습니다. 나는 이것을 시도하고 작동 시키려면 다음과 같은 일을했다. 코드 작성자가 컨텐츠보기를 설정하기 위해 포함 된 예제 코드를 사용하는 것만 큼 보이는 것처럼 보입니다. 레이아웃에서 간단한 xml 파일을 만들면 제대로 작동합니다.

나는 왜 커버 플로우가 그토록 잘 작동하는지 이해하지 못하고, 레이아웃 안에 배치하면 작동하지 않습니다.

이 기능을 수행하기 위해 수행해야 할 사항에 대한 체크리스트가 있습니까?

커버 플로우 코드에 대한 저자는 두 사람은 자신의 맞춤 XML보기 나는이 라인에 대한 주석을 제거

  //Use this if you want to use XML layout file 
    //setContentView(R.layout.main); 
    //coverFlow = (CoverFlow) findViewById(R.id.coverflow); 

내가 사용할 수 있습니다 할 때 사용할 수있는 샘플과 같은 라인을 주석 추가 된 그들.

은 다음으로는 XML 레이아웃에 다음 코드를 추가

 <com.vagina.destruction.CoverFlow 
     android:id="@+id/coverflow" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 
     </com.vagina.destruction.CoverFlow> 

이 난 일식

다음 클래스를 인스턴스화 할 수없는

의 시각적 레이아웃 편집기에서 무엇입니까 오류 메시지입니다 : - com.vagina.destructon.CoverFlow (열린 클래스, 오류 로그 표시) - com.vagina.destruction.CoverFlowExample (열린 클래스, 오류 로그 표시) 자세한 내용은 오류 로그 (창>보기 표시)를 참조하십시오. 팁 : View.isInEditMode() 코드를 건너 뛸 사용자 정의 뷰에서 이클립스

여기에

및 표시된 커버 플로우 예를 들어 활동

public class CoverFlowExample extends Activity implements OnItemClickListener { 
/** Called when the activity is first created. */ 

int imageCount = 0; 
Cursor cur; 
String toastResult; 
String pathName; 
ArrayList<String> list1 = new ArrayList<String>(); 
private int blocker = 0; 
private int imagePosition; 
private int pathIndex; 
private int indexer; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    CoverFlow coverFlow; 
    coverFlow = new CoverFlow(this); 

    Bundle extras = getIntent().getExtras(); 
    if(extras !=null) { 

    imagePosition = extras.getInt("imagePosition"); 

    } 


    String[] proj2 = {MediaStore.Images.Media.DATA}; 
    Cursor cur2 = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj2, MediaStore.Images.Media.IS_PRIVATE + "='" + 1 +"'", null, null); 

    imageCount = cur2.getCount(); 


    cur2.close(); 

    coverFlow.setAdapter(new ImageAdapter(this)); 

    ImageAdapter coverImageAdapter = new ImageAdapter(this); 

    coverFlow.setAdapter(coverImageAdapter); 

    coverFlow.setSpacing(-10); 
    coverFlow.setSelection(imageCount, true); 

// setContentView(coverFlow); 

    coverFlow.setOnItemClickListener(this); 

    coverFlow.setSelection(imagePosition); 


    coverFlow = (CoverFlow) findViewById(R.id.coverflow); 

    //Use this if you want to use XML layout file 
     setContentView(R.layout.activity_coverflow); 
    coverFlow = (CoverFlow) findViewById(R.id.coverflow); 

    // centers the image on coverflow to the same image selected in the previous activity 
     coverFlow.setBackgroundResource(R.drawable.blanklarge); 

답변

3

사용이

의 시작 코드의 일부이다
 public class CoverFlowExample extends Activity implements OnItemClickListener { 
    /** Called when the activity is first created. */ 

    int imageCount = 0; 
    Cursor cur; 
    String toastResult; 
    String pathName; 
    ArrayList<String> list1 = new ArrayList<String>(); 
    private int blocker = 0; 
    private int imagePosition; 
    private int pathIndex; 
    private int indexer; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     //Use this if you want to use XML layout file 
     setContentView(R.layout.activity_coverflow); 
     CoverFlow coverFlow; 
     coverFlow = (CoverFlow) findViewById(R.id.coverflow); 

/*  CoverFlow coverFlow; 
     coverFlow = new CoverFlow(this); */ 

     Bundle extras = getIntent().getExtras(); 
     if(extras !=null) { 

     imagePosition = extras.getInt("imagePosition"); 

     } 


     String[] proj2 = {MediaStore.Images.Media.DATA}; 
     Cursor cur2 = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj2, MediaStore.Images.Media.IS_PRIVATE + "='" + 1 +"'", null, null); 

     imageCount = cur2.getCount(); 


     cur2.close(); 

     coverFlow.setAdapter(new ImageAdapter(this)); 

     ImageAdapter coverImageAdapter = new ImageAdapter(this); 

     coverFlow.setAdapter(coverImageAdapter); 

     coverFlow.setSpacing(-10); 
     coverFlow.setSelection(imageCount, true); 

     coverFlow.setOnItemClickListener(this); 

     coverFlow.setSelection(imagePosition); 



     // centers the image on coverflow to the same image selected in the previous activity 
      coverFlow.setBackgroundResource(R.drawable.blanklarge); 

기본적으로 문제는 XML에서 물건을 선언하면 setCOntentView를 사용하여 물건을 팽창하면 opbject가 자동 생성된다는 것입니다. findViewById를 사용하여 이미 만든 객체를 가져올 수 있으며 "x = new x()"를 사용하여 다시 만들 필요가 없습니다.

+0

예 !!!!!! 이제 작동합니다 – Kevik

+0

Gr88 :-) ..문제를 겪고있는 다른 사람들이 도움이 될 수 있도록 upvote도 할 수 있습니다. –