видоискатель с разными видами - PullRequest
0 голосов
/ 08 августа 2011

Я хочу построить круг из трех видов, на каждом экране две кнопки для просмотра вперед и далее. Просмотр всех трех связанных с ними видов.У меня есть три макета для каждого вида и три CustomView, которые раздуваются соответственно с макетом.и прежде всего одно действие, которое содержит ViewFlipper.

мои вопросы:

1.Как я могу переключаться между ними с помощью ViewFlipper?
с myFlipper.addView (myView) или я должен использоватьтег внутри макета viewFlipper?

2.как раздувать мой взгляд с помощью соответствующего макета, который я уже пробовал LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.t1, null);

моя деятельность выглядит так

public class Activity1 extends Activity {
   private ViewFlipper flipper;

   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_fliper_layout);
     flipper = (ViewFlipper) findViewById(R.id.flipper);
     myView1 temp1= new myView1 (this); 

     flipper.addView(myView1 , 1);     
     flipper.setDisplayedChild(1);
     }
 }

Ответы [ 3 ]

4 голосов
/ 08 августа 2011
ViewFlipper flipper = (ViewFlipper) findViewById(R.id.flipper);

//Inflate the Views
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v1 = inflater.inflate(R.layout.t1, null);
View v2 = inflater.inflate(R.layout.t2, null);
View v3 = inflater.inflate(R.layout.t3, null);

//Add the views to the flipper
viewFlipper.addView(v1);
viewFlipper.addView(v2);
viewFlipper.addView(v3);

//Move between them
flipper.showNext();
flipper.showPrevious();

http://developer.android.com/reference/android/widget/ViewAnimator.html#showNext()

2 голосов
/ 05 марта 2014

добавление дочернего элемента в видоискатель dyanamically.

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.walk_around_the_store_question, container, false);
    this.initViewControls(view);

    // Set Questions
    this.setViewFlipper(inflater);

    return view;
}

 private void initViewControls(View view)
{
    // getting name of current student.
    String studentName = ApplicationSharedPreference.getInstance(
            WalkAroundTheStoreQuestioneryFragment.this.getActivity()).getStringValue(
            ApplicationConstants.WALK_AROUND_THE_STORE_CURRENT_STUDENT_NAME);

    this.btnSubmitData = (Button) view.findViewById(R.id.btnSubmitData);
    this.btnSubmitData.setOnClickListener(this.btnClickListener);

    this.txtTitleName = (TextView) view.findViewById(R.id.txtTitleName);
    this.txtTitleName.setText(studentName);

    this.viewFlipper = (ViewFlipper) view.findViewById(R.id.viewflipper);
    this.imgPrevious = (ImageView) view.findViewById(R.id.imgPrevious);
    this.imgNext = (ImageView) view.findViewById(R.id.imgNext);

    this.imgPrevious.setOnClickListener(this.btnClickListener);
    this.imgNext.setOnClickListener(this.btnClickListener);

    if (0 == WalkAroundTheStoreQuestioneryFragment.this.viewFlipper.getDisplayedChild())
    {
        WalkAroundTheStoreQuestioneryFragment.this.imgPrevious.setVisibility(View.INVISIBLE);
    }
}

/**
 *  Button Click event.
 */
private OnClickListener btnClickListener = new View.OnClickListener()
{
    @Override
    public void onClick(View v)
    {
        switch (v.getId())
        {
        case R.id.imgPrevious:
            WalkAroundTheStoreQuestioneryFragment.this.imgNext.setVisibility(View.VISIBLE);
            // if viewflipper first child then hide previous button
            if (1 == WalkAroundTheStoreQuestioneryFragment.this.viewFlipper.getDisplayedChild())
            {
                WalkAroundTheStoreQuestioneryFragment.this.imgPrevious.setVisibility(View.INVISIBLE);
            }

            // set animations for previous question move
            WalkAroundTheStoreQuestioneryFragment.this.viewFlipper.setInAnimation(SliderAnimation
                    .inFromLeftAnimation());
            WalkAroundTheStoreQuestioneryFragment.this.viewFlipper.setOutAnimation(SliderAnimation
                    .outToRightAnimation());
            WalkAroundTheStoreQuestioneryFragment.this.viewFlipper.showPrevious();
            break;
        case R.id.imgNext:
            WalkAroundTheStoreQuestioneryFragment.this.imgPrevious.setVisibility(View.VISIBLE);

            // if viewflipper last child then hide next button.
            if (WalkAroundTheStoreQuestioneryFragment.this.viewFlipper.getChildCount() == WalkAroundTheStoreQuestioneryFragment.this.viewFlipper
                    .getDisplayedChild())
            {
                WalkAroundTheStoreQuestioneryFragment.this.imgNext.setVisibility(View.INVISIBLE);
            }

            // set animations for next question move
            WalkAroundTheStoreQuestioneryFragment.this.viewFlipper.setInAnimation(SliderAnimation
                    .inFromRightAnimation());
            WalkAroundTheStoreQuestioneryFragment.this.viewFlipper.setOutAnimation(SliderAnimation
                    .outToLeftAnimation());

            WalkAroundTheStoreQuestioneryFragment.this.viewFlipper.showNext();
            break;
        case R.id.btnSubmitData:
            Toast.makeText(WalkAroundTheStoreQuestioneryFragment.this.getActivity(), "btnSubmitData",
                    Toast.LENGTH_LONG).show();
            break;
        default:
            break;
        }
    }
};

/**
 * @param inflater 
 * 
 */
private void setViewFlipper(LayoutInflater inflater)
{
    for (int i = 1; i < 10; i++)
    {
        View view1 = inflater.inflate(R.layout.walk_around_store_quetions_inflate, null);
        this.viewFlipper.addView(view1);

        this.txtQuestions = (TextView) view1.findViewById(R.id.txtQuestions);
        this.txtQuestions.setText("First Question :" + i);

        this.txtQuestionsSub1 = (TextView) view1.findViewById(R.id.txtQuestionsSub1);
        this.txtQuestionsSub1.setText("SubPoint :" + i + ".1");
        this.spnQuestionsSub1 = (Spinner) view1.findViewById(R.id.spnQuestionsSub1);

        this.txtQuestionsSub2 = (TextView) view1.findViewById(R.id.txtQuestionsSub2);
        this.txtQuestionsSub2.setText("SubPoint :" + i + ".2");
        this.spnQuestionsSub2 = (Spinner) view1.findViewById(R.id.spnQuestionsSub2);

        this.txtQuestionsSub3 = (TextView) view1.findViewById(R.id.txtQuestionsSub3);
        this.txtQuestionsSub3.setText("SubPoint :" + i + ".3");
        this.spnQuestionsSub3 = (Spinner) view1.findViewById(R.id.spnQuestionsSub3);

        this.txtQuestionsSub4 = (TextView) view1.findViewById(R.id.txtQuestionsSub4);
        this.txtQuestionsSub4.setText("SubPoint :" + i + ".4");
        this.spnQuestionsSub4 = (Spinner) view1.findViewById(R.id.spnQuestionsSub4);
    }
}
0 голосов
/ 21 сентября 2016

Это может помочь вам.

ViewFlipper viewFlipper= (ViewFlipper) findViewById(R.id.flipper);

View v1 = LayoutInflater.from(mContext).inflate(R.layout.layout_1, null, false);
View v2 = LayoutInflater.from(mContext).inflate(R.layout.layout_2, null, false);
View v3 = LayoutInflater.from(mContext).inflate(R.layout.layout_3, null, false);
View v4 = LayoutInflater.from(mContext).inflate(R.layout.layout_4, null, false);

viewFlipper.addView(v1);
viewFlipper.addView(v2);
viewFlipper.addView(v3);
viewFlipper.addView(v4);

viewFlipper.showNext();
viewFlipper.showPrevious();
...