2012-01-30 5 views
2

저는 jason fry의 SwipeView를 사용하고 있습니다. 이미지 뷰용으로 사용하고 있는데, 레이아웃으로 바꾸는 데 어려움을 겪고 있습니다. 어떤 도움이 감사 감사이미지 대신 레이아웃 용 SwipeView 사용

패키지 com.example을 나는 텍스트 뷰와 이미지 뷰를 대체하지만 어떻게 레이아웃 로 이미지 뷰를 대체 할 경우 작동 순간에

;

import android.graphics.Typeface; 
import android.text.Layout; 
import android.widget.LinearLayout; 
import android.widget.TextView; 
import com.example.R; 
import uk.co.jasonfry.android.tools.ui.PageControl; 
import uk.co.jasonfry.android.tools.ui.SwipeView; 
import uk.co.jasonfry.android.tools.ui.SwipeView.OnPageChangedListener; 
import android.app.Activity; 
import android.os.Bundle; 
import android.widget.FrameLayout; 
import android.widget.ImageView; 

public class MyActivity extends Activity 
{ 
SwipeView mSwipeView; 

LinearLayout ll; 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    ll = new LinearLayout(this); 
    ll = loadLayout(); 

    PageControl mPageControl = (PageControl) findViewById(R.id.page_control); 
    mSwipeView = (SwipeView) findViewById(R.id.swipe_view); 

    //loadImages(); 

    for(int i=0; i<4;i++) 
    { 
     mSwipeView.addView(new FrameLayout(this)); 
    } 

    TextView i0 = new TextView(this); 
    TextView i1 = new TextView(this); 
    i0.setText("page 1"); 
    i1.setText("page 2"); 

    ((FrameLayout) mSwipeView.getChildContainer().getChildAt(0)).addView(ll); 
    ((FrameLayout) mSwipeView.getChildContainer().getChildAt(1)).addView(ll); 

    SwipeImageLoader mSwipeImageLoader = new SwipeImageLoader(); 

    mSwipeView.setOnPageChangedListener(mSwipeImageLoader); 
    mSwipeView.setPageControl(mPageControl); 
} 

private class SwipeImageLoader implements OnPageChangedListener 
{ 

    public void onPageChanged(int oldPage, int newPage) 
    { 
     if(newPage>oldPage)//going forwards 
     { 
      if(newPage != (mSwipeView.getPageCount()-1))//if at the end, don't load one page after the end 
      { 
       TextView v = new TextView(MyActivity.this); 
       v.setText("page :"+(newPage+1)); 
       ((FrameLayout) mSwipeView.getChildContainer().getChildAt(newPage+1)).addView(ll); 
      } 
      if(oldPage!=0)//if at the beginning, don't destroy one before the beginning 
      { 
       ((FrameLayout) mSwipeView.getChildContainer().getChildAt(oldPage-1)).removeAllViews(); 
      } 

     } 
     else //going backwards 
     { 
      if(newPage!=0)//if at the beginning, don't load one before the beginning 
      { 

       TextView v = new TextView(MyActivity.this); 
       v.setText("page :"+(newPage+1)); 
       ((FrameLayout) mSwipeView.getChildContainer().getChildAt(newPage-1)).addView(ll); 
      } 
      if(oldPage != (mSwipeView.getPageCount()-1))//if at the end, don't destroy one page after the end 
      { 
       ((FrameLayout) mSwipeView.getChildContainer().getChildAt(oldPage+1)).removeAllViews(); 
      } 
     } 

    } 

} 

private LinearLayout loadLayout() 
{ 
    //logo 
    ImageView logo = new ImageView(this); 
    logo.setImageResource(R.drawable.image001); 
    logo.setLayoutParams(new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 

    // espace 
    TextView espace = new TextView(this); 
    espace.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 
    espace.setText(" "); 

    // wrap prest 
    LinearLayout wprest = new LinearLayout(this); 

    //Prestation 
    TextView txt_pres = new TextView(this); 
    txt_pres.setText(" Prestation n° "); 
    txt_pres.setTextColor(R.color.black); 
    // plaid 
    TextView plaid = new TextView(this); 
    plaid.setTextColor(R.color.black); 
    plaid.setTypeface(null, Typeface.BOLD); 
    plaid.setText("4558"); 
    // - 
    TextView tiret = new TextView(this); 
    tiret.setTextColor(R.color.black); 
    tiret.setTypeface(null, Typeface.BOLD); 
    tiret.setText(" - "); 
    // plaid 
    TextView platyp = new TextView(this); 
    platyp.setTextColor(R.color.black); 
    platyp.setTypeface(null, Typeface.BOLD); 
    platyp.setText("ECHANGE"); 

    wprest.addView(txt_pres); 
    wprest.addView(plaid); 
    wprest.addView(tiret); 
    wprest.addView(platyp); 



    LinearLayout ll = new LinearLayout(this); 

    ll.setBackgroundResource(R.color.white); 
    ll.setOrientation(LinearLayout.VERTICAL); 
    ll.setLayoutParams(new  LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,  LinearLayout.LayoutParams.FILL_PARENT)); 
    ll.addView(logo); 
    ll.addView(espace); 
    ll.addView(wprest); 

    return ll; 
} 
} 

답변

2

왜 같은 다른 ViewPager 라이브러리를 시도하지 않습니다

  • 안드로이드-viewflow (https://github.com/pakerfeldt/android-viewflow)
  • 안드로이드 ViewPagerIndicator (https://github.com/JakeWharton/Android-ViewPagerIndicator)

사용하기 때문에 쉽게 어린이 레이아웃을 맞춤 설정할 수 있습니다.

가장 인기있는 ViewPager 라이브러리입니다. 자세한 내용은 시장에서 내 "Android UI 패턴"앱을 확인하십시오 : https://market.android.com/details?id=com.groidify.uipatterns. 개발자에게 유용한 샘플이 많이 있습니다.

+0

덕분에 jason fry의 예를 찾을 수있었습니다. 위대한 애플 리케이션에 의해 –

+0

내가 IntelliJ IDEA를 사용하고있어, 나는 그것을 불가능 ViewFlow를 구현하는 것을 발견했습니다 –

+0

SwipeView는 내가 원래 그것을 만들 때 다른 일을했기 때문에 존재합니다. 나는 SwipeView의 찬반 양론을 android-viewflow, greendroid one, 공식적인 안드로이드 중 하나를 호환성 팩으로 얻을 수있는 점을 비교해 본적이 없다. 그래서 어느 것이 가장 좋은지 말할 수 없었다. :) – jsonfry

0

yo

나는이 라이브러리를 단지 이미지 이상을 위해 사용합니다. 복잡한 레이아웃에서도 사용 했으므로 작동합니다.

이후 새로운 레이아웃 객체를 추가했지만 문서화되지 않았거나 사용법 예제를 만들었습니다. (바쁜 사람입니다! : p) 그 중 하나는 PageView라고하며, 다음과 같은 어댑터를 사용합니다. ListView, 그래서 당신이 ListView를 사용하는 방법을 알고 있다면 이것을 사용할 수 있어야합니다. 열쇠는 .setAdapter (BaseAdapter 어댑터) 메소드를 사용하고 있습니다.

github에서 최신 버전을 사용하고 있는지 확인하십시오. github에서 PageView 클래스 코드로 바로 연결되는 링크는 다음과 같습니다. https://github.com/fry15/uk.co.jasonfry.android.tools/blob/master/src/uk/co/jasonfry/android/tools/widget/PageView.java

관련 문제