qq_40333028
西米啊
2017-09-21 02:17

android中用tabLayout写底部导航栏时切换按钮时只切换布局,布局对应的活动没反应

  • android

public class Fragment1 extends Fragment {
private LuckyPanView mLuckyPanView;
private ImageView mStartBtn;
@Nullable
@Override

public View onCreateView(LayoutInflater inflater,
                         @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment1, container, false);

    mLuckyPanView = (LuckyPanView) rootView.findViewById(R.id.id_luckypan);
    mStartBtn = (ImageView) rootView.findViewById(R.id.id_start_btn);

    return inflater.inflate(R.layout.fragment1,container, false);
}

public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Log.d("string","123");
            //抽奖转盘的开始按钮的点击事件
    mStartBtn.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            int count = Integer.valueOf((int)(Math.random()*1000));
            //int count = 1;
            if (!mLuckyPanView.isStart())
            {
                //当index为0的时候停在"单反"的位置,当index为1的时候停在"ipad"的位置,
                // 当index为-1和2的时候停在"恭喜发财"的位置,当index为3的时候停在"iphone"的位置
                //当index为4的时候停在"服装一套"的位置
                Log.d("int","444444444");
                if(count==1){
                    mLuckyPanView.luckyStart(1);
                }else if(count>=2 && count<=3){
                    mLuckyPanView.luckyStart(0);
                }else if(count>=4 && count<=8){
                    mLuckyPanView.luckyStart(3);
                }else if(count>=9 && count<=28){
                    mLuckyPanView.luckyStart(4);
                }else if(count>=29 && count<=500){
                    mLuckyPanView.luckyStart(2);
                }else if(count>=500 && count<=1000){
                    mLuckyPanView.luckyStart(-1);
                }
                mStartBtn.setImageResource(R.drawable.stop);
            } else
            {
                if (!mLuckyPanView.isShouldEnd())

                {
                    mLuckyPanView.luckyEnd();
                    mStartBtn.setImageResource(R.drawable.start);
                }
            }
        }
    });


}

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答