猿问

如何正确的在Fragment中使用ViewFlipper?

public class OneFgm extends Fragment{
    private int[] image_resource = {
            R.drawable.abookapart1,
            R.drawable.bg2015071003,
            R.drawable.bg2015071004,
            R.drawable.bg2015071010
    };
    public OneFgm() {
    }
    public ImageView getImageView(int res_id){
        ImageView imageView = new ImageView(getContext());
        imageView.setBackgroundResource(res_id);
        return imageView;
    }

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

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.home_layout,container,false);
        ViewFlipper flipper = (ViewFlipper) view.findViewById(R.id.flipper);
        for (int i : image_resource){
            flipper.addView(getImageView(i));
        }
        flipper.setInAnimation(this.getContext(),R.anim.right_enter);
        flipper.setOutAnimation(this.getContext(),R.anim.left_out);
        flipper.startFlipping();
        return view;
    }
}

不知道为什么没有效果,甚至连图都没有..

码上有媳妇
浏览 2352回答 1
1回答

Mopel

你没有为你新建的ImageView指定宽度和高度,默认宽高为0,自然在界面上就看不到
随时随地看视频慕课网APP

相关分类

Android
我要回答