我正在尝试实现 viewPager ,在其中我在同一活动的两个片段之间导航。我还添加了 PagerTabStrip。我只做了一个小样本,但由于某种原因它剪切了片段。它也不显示布局中定义的按钮
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class MenuFragment extends Fragment
{
@Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView( LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState )
{
View v = inflater.inflate(R.layout.fragment_menu, parent, false);
TextView textShow = (TextView)v.findViewById(R.id.textViewMenu);
textShow.setText( "works" );
return v;
}
}
<?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="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textViewMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
/>
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center|bottom">
<Button
android:id="@+id/true_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/false_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>