onAttach(Activity)
onCreateView(LayoutInflater, ViewGroup,Bundle)
onActivityCreated(Bundle)
onDestoryView()
onDetach()
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemasandroidcom/apk/res/android"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@drawable/title_bar" >
<ImageButton
android:id="@+id/id_title_left_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="3dp"
android:background="@drawable/showleft_selector" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="我不是微信"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
package comzhyzhy_fragments;
import androidappFragment;
import androidosBundle;
import androidviewLayoutInflater;
import androidviewView;
import androidviewViewOnClickListener;
import androidviewViewGroup;
import androidwidgetImageButton;
import androidwidgetToast;
public class TitleFragment extends Fragment
{
private ImageButton mLeftMenu;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflaterinflate(Rlayoutfragment_title, container, false);
mLeftMenu = (ImageButton) viewfindViewById(Ridid_title_left_btn);
mLeftMenusetOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
ToastmakeText(getActivity(),
"i am an ImageButton in TitleFragment ! ",
ToastLENGTH_SHORT)show();
}
});
return view;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemasandroidcom/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text="使用Fragment做主面板"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
package com.zhy.zhy_fragments;
import androidappFragment;
import androidosBundle;
import androidviewLayoutInflater;
import androidviewView;
import androidviewViewGroup;
public class ContentFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
return inflaterinflate(Rlayoutfragment_content, container, false);
}
}
package com.zhy.zhy_fragments;
import androidappActivity;
import androidosBundle;
import androidviewWindow;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
superonCreate(savedInstanceState);
requestWindowFeature(WindowFEATURE_NO_TITLE);
setContentView(Rlayoutactivity_main);
}
}
<RelativeLayout xmlns:android="http://schemasandroidcom/apk/res/android"
xmlns:tools="http://schemasandroidcom/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/id_fragment_title"
android:name="comzhyzhy_fragmentsTitleFragment"
android:layout_width="fill_parent"
android:layout_height="45dp" />
<fragment
android:layout_below="@id/id_fragment_title"
android:id="@+id/id_fragment_content"
android:name="comzhyzhy_fragmentsContentFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemasandroidcom/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/id_fragment_title"
android:name="comzhyzhy_fragmentsTitleFragment"
android:layout_width="fill_parent"
android:layout_height="45dp" />
<include
android:id="@+id/id_ly_bottombar"
android:layout_width="fill_parent"
android:layout_height="55dp"
android:layout_alignParentBottom="true"
layout="@layout/bottombar" />
<FrameLayout
android:id="@+id/id_content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/id_ly_bottombar"
android:layout_below="@id/id_fragment_title" />
</RelativeLayout>
package com.zhy.zhy_fragments;
import androidappActivity;
import androidappFragmentManager;
import androidappFragmentTransaction;
import androidosBundle;
import androidviewView;
import androidviewViewOnClickListener;
import androidviewWindow;
import androidwidgetLinearLayout;
public class MainActivity extends Activity implements OnClickListener
{
private LinearLayout mTabWeixin;
private LinearLayout mTabFriend;
private ContentFragment mWeixin;
private FriendFragment mFriend;
@Override
protected void onCreate(Bundle savedInstanceState)
{
superonCreate(savedInstanceState);
requestWindowFeature(WindowFEATURE_NO_TITLE);
setContentView(Rlayoutactivity_main);
// 初始化控件和声明事件
mTabWeixin = (LinearLayout) findViewById(Ridtab_bottom_weixin);
mTabFriend = (LinearLayout) findViewById(Ridtab_bottom_friend);
mTabWeixinsetOnClickListener(this);
mTabFriendsetOnClickListener(this);
// 设置默认的Fragment
setDefaultFragment();
}
private void setDefaultFragment()
{
FragmentManager fm = getFragmentManager();
FragmentTransaction transaction = fmbeginTransaction();
mWeixin = new ContentFragment();
transactionreplace(Ridid_content, mWeixin);
transactioncommit();
}
@Override
public void onClick(View v)
{
FragmentManager fm = getFragmentManager();
// 开启Fragment事务
FragmentTransaction transaction = fmbeginTransaction();
switch (vgetId())
{
case Ridtab_bottom_weixin:
if (mWeixin == null)
{
mWeixin = new ContentFragment();
}
// 使用当前Fragment的布局替代id_content的控件
transactionreplace(Ridid_content, mWeixin);
break;
case Ridtab_bottom_friend:
if (mFriend == null)
{
mFriend = new FriendFragment();
}
transactionreplace(Ridid_content, mFriend);
break;
}
// transactionaddToBackStack();
// 事务提交
transactioncommit();
}
}
package com.zhy.zhy_fragments;
import androidappFragment;
import androidosBundle;
import androidviewLayoutInflater;
import androidviewView;
import androidviewViewGroup;
public class FriendFragment extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
return inflaterinflate(Rlayoutfragment_friend, container, false);
}
}
getFragmentManager() // v4中,getSupportFragmentManager
FragmentTransaction transaction = fm.benginTransatcion();//开启一个事务 transaction.add()
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有