2 回答

TA貢獻96條經驗 獲得超96個贊
fragment是依附于activity的
fragment就是一個小activity
所以基本activity能做到的fragment都能做到,你只需要百度fragment的用法,看看fragment的生命周期,就像學activity那樣學就行了

TA貢獻9條經驗 獲得超2個贊
第一步:
在Acitivity中完成替換
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.layout.frament,new MyFragemnt()).commit();
第二步:
public class MyFragment extends Fragment {
? ?@Nullable
? ?@Override
? ?public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
? ? ? ?View view = View.inflate(context, R.layout.gradview, null); //注意這里的?R.layout.gradview? 就是你需要設置的GraidView布局?
return view;
? ?}
}
- 2 回答
- 0 關注
- 1638 瀏覽
添加回答
舉報