具有不同视图的viewflipper

发布于 2024-11-28 12:55:49 字数 868 浏览 3 评论 0原文

我想构建三个视图的圆圈,在每个视图上有两个按钮用于上一个和下一个视图由它们连接的所有三个视图。 我为每个视图提供了三个布局,以及三个随布局相应膨胀的 CustomView。 最重要的是一个包含 ViewFlipper 的 Activity。

我的问题是:

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

I want to build circle of three View,On each view two buttons to prev and next View all the three View connected by them.
I have three layout for each View, and three CustomView that inflate accordingly with the layout.
and above all one Activity that hold ViewFlipper.

my questions is:

1.how could I flip between them with viewFlipper?
with myFlipper.addView(myView) or should i use tag inside the viewFlipper layout?

2.how to inflate my view with the relevant Layout
I already try LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.t1, null);

my activity looks like this

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

Spring初心 2024-12-05 12:55:50
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()

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()

乖不如嘢 2024-12-05 12:55:50

在 viewflipper 中动态添加子项。

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

adding child in viewflipper 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);
    }
}
£冰雨忧蓝° 2024-12-05 12:55:50

这可能对你有帮助。

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();

This might help you.

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文