Android LinearLayout加载Fragment
生活随笔
收集整理的這篇文章主要介紹了
Android LinearLayout加载Fragment
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
為LinearLayout添加Fragment效果
1、創建Fragment
public class Fragment1 extends Fragment {public static Fragment1 getInstance(Bundle bundle) {Fragment1 fg = new Fragment1();fg.setArguments(bundle);return fg;}protected View contentView;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {contentView = inflater.inflate(R.layout.fragment1, container, false);initViews();return contentView;}public void initViews(){TextView textView =(TextView)contentView.findViewById(R.id.f1te);textView.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Toast.makeText(getContext(),"ssssf1",Toast.LENGTH_SHORT).show();}});}}附activity_main.xml
<LinearLayoutandroid:id="@+id/music_control"android:layout_width="match_parent"android:layout_height="60dp"android:layout_alignParentBottom="true"android:padding="5dp"android:orientation="horizontal"android:background="@color/grey"> </LinearLayout>2、添加方法
/*** 用于設置底部的控制音樂播放的fragment*/ private void setBottomController() {FragmentManager fragmentManager = getSupportFragmentManager();FragmentTransaction transaction = fragmentManager.beginTransaction();transaction.add(R.id.music_control,new Fragment1());transaction.commit(); }總結
以上是生活随笔為你收集整理的Android LinearLayout加载Fragment的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用maven构建的Spring boo
- 下一篇: Android 人脸识别进行实名验证de