1

我正在尝试使用操作栏选项卡,但我有一些问题。

  1. 我从开发人员博客中看到我需要使用 Fragment 布局。我在想要的布局按钮中有它们之间的边距取决于屏幕尺寸。我以前在相对布局中做,但在片段布局中它不起作用。有没有办法从java代码改变视图位置?

  2. 我的观点不再响应 setOnClickListener。我尝试使用此代码:

    查看 homePageLayout = View.inflate(this, R.layout.home_page, null);

    锻炼墙 = (ImageButton) homePageLayout.findViewById(R.id.workoutWall);

    锻炼墙.setOnClickListener(this);

我的片段代码:

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

        if(tab.getPosition() == 0)
        {
            ft.add(R.id.fragment_place, fragmentHome, null);
            setTheMarging();
        }
        else
            ft.add(R.id.fragment_place, fragmentExtra, null);
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

    @Override
      public void onRestoreInstanceState(Bundle savedInstanceState) {
        // Restore the previously serialized current tab position.
        if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
          getActionBar().setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
        }
      }

     @Override
      public void onSaveInstanceState(Bundle outState) {
        // Serialize the current tab position.
        outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getActionBar()
            .getSelectedNavigationIndex());
      }

     public static class HomePageFragment extends Fragment
     {
            public static final String ARG_SECTION_NUMBER = "placeholder_text";

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {

                return inflater.inflate(R.layout.home_page, container, false);
            }
     }

     public static class ExtrasFragment extends Fragment
     {
            public static final String ARG_SECTION_NUMBER = "placeholder_text";

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {

                return inflater.inflate(R.layout.extras, container, false);
            }
     }

Thanks for helping
4

0 回答 0