80,349
社区成员
发帖
与我相关
我的任务
分享
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab_P1 = actionBar.newTab();
Tab_P1.setCustomView(R.layout.tab_layout_dong);
Tab_P2 = actionBar.newTab();
Tab_P2.setCustomView(R.layout.tab_layout_nan);
fragment_P1 = new Fragment_P1();
MyTabListener AListener=new MyTabListener(fragment_P1);
Tab_P1.setTabListener(AListener);
fragment_P2 = new Fragment_P2();
MyTabListener BListener=new MyTabListener(fragment_P2);
Tab_P2.setTabListener(BListener);
actionBar.addTab(Tab_P1);
actionBar.addTab(Tab_P2);
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.fragment_place, fragment_P1);
transaction.commit();
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<FrameLayout
android:id="@+id/fragment_place"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</FrameLayout>
</RelativeLayout>
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_layout_dong, container, false); //①<--这样可以正常
//View view = new MySurfaceView(this.getActivity()); //②这样就显示不出来
return view;
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/fragment_dong_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center"
android:text="test"
/>
</LinearLayout>
public MySurfaceView(Context aContext)
{
super(aContext);
context=aContext;
holder = this.getHolder();
holder.addCallback(this);
}
public void surfaceCreated(SurfaceHolder holder) {
myThread = new Thread(new MyRunnable());
runFlag = true;
myThread.start();
}
class MyRunnable implements Runnable {
@Override
public void run()
{
//这里随便画几条线段测试
}