为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(); }