tabview中的片段

时间:2012-02-21 10:18:07

标签: android android-layout android-widget

我正在创建一个标签视图,当单击一个按钮时,它必须移动到另一个屏幕,当我尝试使用上面的代码实现它时它正在改变到另一个屏幕,但按钮仍然可见下一个屏幕,我想要下一个屏幕应覆盖整个屏幕

public class Tab1Fragment extends Fragment  {
LinearLayout mLayout;
/** (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater,      android.view.ViewGroup, android.os.Bundle)
 */
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {

if (container == null) {


    return null;
}

LinearLayout theLayout = (LinearLayout)inflater.inflate(R.layout.tab_frag1_layout, container, false);

        // Register for the Button.OnClick event

        Button b = (Button)theLayout.findViewById(R.id.button1);

        b.setOnClickListener(new View.OnClickListener() {



            @Override

            public void onClick(View v) {

                 Fragment mFragment = new third_fragment_view();
                 android.support.v4.app.FragmentTransaction ft = getFragmentManager().beginTransaction();

                 ft.replace(R.id.container, mFragment);
                 ft.addToBackStack(null);
                 ft.commit();   


            }

        });

return theLayout;

}
} 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#00bfff"
android:id="@+id/container1" >

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

</LinearLayout>  

enter image description here

1 个答案:

答案 0 :(得分:0)

覆盖整个屏幕的Ui不使用Fragments.Use Intents

 b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
       Intent intent=new Intent();
       intent.setClass(thisactivity.class,targetactivity.class);
       startActivity(intent);
       }
    });