android: layout_height="fill_parent" of ViewPager does not work

0

I have a ViewPage that does not work android:layout_height="fill_parent" , it does not show anything on the screen, but if I determine a value ex: android:layout_height="500dp" the height determines.

.xml

<RelativeLayout
    android:id="@+id/main_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:elevation="6dp"
        android:minHeight="?attr/actionBarSize"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/page"
        android:layout_width="match_parent"
        android:layout_height="fill_parent" <--não trabalha
        android:layout_below="@id/tab_layout" />

</RelativeLayout>

.java

public class AlterarOsFragment extends Fragment implements View.OnClickListener {
    public static final String TAG = "";
    DataBaseHandler db;
    int numeroOs;


    public AlterarOsFragment(int numeroOs) {
        this.numeroOs = numeroOs;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_alterar_os, container, false);
        db = new DataBaseHandler(getActivity());

        TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tab_layout);
        tabLayout.addTab(tabLayout.newTab().setText(getResources().getString(R.string.informacoes)));
        tabLayout.addTab(tabLayout.newTab().setText(getResources().getString(R.string.servicos)));
        tabLayout.addTab(tabLayout.newTab().setText(getResources().getString(R.string.orcamento)));
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

        final ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.page);
        final PagerAdapter adapter = new TabAdapter(getActivity().getSupportFragmentManager(), tabLayout.getTabCount(), numeroOs);

        viewPager.setAdapter(adapter);


        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
                }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        return rootView;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    @Override
    public void onClick(View view) {

    }
}
    
asked by anonymous 20.08.2016 / 23:17

1 answer

0

It is recommended that developers use the new "match_parent" nomenclature. And for older applications, of course compatibility still exists. Try changing your layout width to match_parent .

android:layout_width="match_parent"

What is the function of match_parent?

The function of match_parent is to give a special value to the height or width requested by a View.

Use match_parent because there is no difference if you are in versions of API 8+, and since mobiles = > Android 2.2 is advisable to use match_parent, but for compatibility issue for previous versions there is still fill_parent.

  

NOTE: In versions of Android API 1.6 to 2.1 it is advisable   use fill_parentpois using match_parent in these versions occur certain   errors, then in these API versions use fill_parent.

According to the official documentation of Android itself, it specifies that they are the same thing and that there is no difference in using one or the other.

link

    
21.08.2016 / 00:58