如何在片段中添加脚蹼?

问题描述 投票:-1回答:1

大家好,我正在片段中创建一些图像的鳍状肢(幻灯片)。请大家帮我添加它。这是我尝试的代码。

    public class HomeFragment extends Fragment {
    ViewFlipper v_flipper;
    public HomeFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_home, container, false);
        v_flipper=
    }
}

此活动的xml文件为

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_red_light">

    <ViewFlipper
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:layout_centerHorizontal="true"
        android:id="@+id/v_flipper"
        android:layout_margin="7dp">

    </ViewFlipper>
</RelativeLayout>

我无法将其写为v_flipper= view.findViewById(R.id.v_flipper);

但是当我将view.findViewById与按钮或其他任何东西一起使用时,它可以完美地在片段中工作。任何可以帮助我的人....?

这里是更新的代码

  public class HomeFragment extends Fragment {
    public HomeFragment() {
        // Required empty public constructor
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_home, container, false);
        ViewFlipper v_flipper= view.findViewById(R.id.v_flipper);
        return view;
    }
}
android android-fragments slider android-fragmentactivity android-viewflipper
1个回答
0
投票

尝试一下:

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_home, container, false);

         ViewFlipper v_flipper= view.findViewById(R.id.v_flipper);
          return view;
        }
© www.soinside.com 2019 - 2024. All rights reserved.