操作栏选项卡

时间:2013-08-22 18:28:31

标签: android android-fragments

我试图使用操作栏标签,我有一些问题。

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

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

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

    workoutWall =(ImageButton)homePageLayout.findViewById(R.id.workoutWall);

    workoutWall.setOnClickListener(本);

  3. 我的fragemnts代码:

        @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
    

0 个答案:

没有答案