Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't understand how to attach fragment to activity #9

Closed
ghost opened this issue Apr 21, 2015 · 5 comments
Closed

Don't understand how to attach fragment to activity #9

ghost opened this issue Apr 21, 2015 · 5 comments
Labels

Comments

@ghost
Copy link

ghost commented Apr 21, 2015

I am using this in my activity but activity only shows the tabs but no fragment content...

Activity Class:

public class ActivityUserProfile extends ActionBarActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_profile);

        FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
                getSupportFragmentManager(), FragmentPagerItems.with(ActivityUserProfile.this)
                .add(R.string.title_basic, FragmentProfileBasic.class)
                .create());

        ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
        viewPager.setAdapter(adapter);

        SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
        viewPagerTab.setViewPager(viewPager);
    }
}

Fragment Class:

public class FragmentProfileBasic extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_profile_basic, container, false);
        return rootView;
    }
}
@ogaclejapan
Copy link
Owner

Hi, @mrdarpan

This code I think no problem.
Can I view the layout file here? 
R.layout.activity_user_profile

Fragment is using the support version?

@ghost
Copy link
Author

ghost commented Apr 21, 2015

activity_user_profile

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:font="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="10"
                android:padding="@dimen/fragment_default_padding"
                android:background="@color/color_light_gray"
                android:visibility="visible">

                <ImageView
                    android:id="@+id/profilePicture"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="3"
                    android:minWidth="100dp"
                    android:minHeight="100dp"
                    android:background="@color/color_dark_gray"
                    android:padding="2dp"
                    android:scaleType="fitXY" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingLeft="@dimen/fragment_default_padding"
                    android:paddingRight="@dimen/fragment_default_padding"
                    android:orientation="vertical"
                    android:layout_weight="7">

                    <net.kianoni.fontloader.TextView
                        android:id="@+id/userName"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="User Name"
                        android:textSize="18sp"
                        font:fontFile="fonts/Raleway-Bold.ttf" />

                    <net.kianoni.fontloader.TextView
                        android:id="@+id/userEmail"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Profile: 10% Completed"
                        android:textSize="16sp"
                        font:fontFile="fonts/Raleway-Regular.ttf" />

                </LinearLayout>

            </LinearLayout>

            <com.ogaclejapan.smarttablayout.SmartTabLayout
                android:id="@+id/viewpagertab"
                android:layout_width="match_parent"
                android:layout_height="48dp"
                app:stl_indicatorAlwaysInCenter="false"
                app:stl_indicatorInFront="true"
                app:stl_indicatorInterpolation="smart"
                app:stl_indicatorColor="@color/color_dark_orange"
                app:stl_indicatorThickness="4dp"
                app:stl_indicatorCornerRadius="0dp"
                app:stl_underlineColor="@color/color_dark_orange"
                app:stl_underlineThickness="1dp"
                app:stl_dividerColor="@color/color_dark_orange"
                app:stl_dividerThickness="1dp"
                app:stl_defaultTabTextAllCaps="true"
                app:stl_defaultTabTextColor="#FC000000"
                app:stl_defaultTabTextSize="12sp"
                app:stl_defaultTabTextHorizontalPadding="16dp"
                app:stl_defaultTabTextMinWidth="0dp"
                app:stl_distributeEvenly="true"/>

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@id/viewpagertab" />

        </LinearLayout>

    </ScrollView>

</LinearLayout>

@ogaclejapan
Copy link
Owner

Hi, @mrdarpan
Do works!
Add android:fillViewport="true"

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        ...

    </ScrollView>

The problem is not associated with this library... :o

@NhenDen
Copy link

NhenDen commented Apr 11, 2016

Hi ogaclejapan.
I add Scrollview with smart tab layout but Scrollview not working :(
Help me.
Code of me:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="@dimen/PADDING_APP"
    android:layout_marginLeft="@dimen/PADDING_APP"
    android:layout_marginRight="@dimen/PADDING_APP"
    android:layout_marginTop="@dimen/PADDING_APP"
    android:fillViewport="true"
    android:scrollbars="none">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/fragment_login_imgCover"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/logo" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginTop="-49dp"
                android:alpha="0.3"
                android:background="@color/colorWhite" />

        </LinearLayout>

        <com.ogaclejapan.smarttablayout.SmartTabLayout
            android:id="@+id/fragment_home_viewpagertab"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:layout_marginTop="-48dp"
            android:background="@null"
            app:stl_clickable="true"
            app:stl_customTabTextLayoutId="@layout/tab_item_home"
            app:stl_customTabTextViewId="@+id/tab_item_home_textView"
            app:stl_defaultTabBackground="?attr/selectableItemBackground"
            app:stl_defaultTabTextAllCaps="false"
            app:stl_defaultTabTextColor="@color/colorTextDemo"
            app:stl_defaultTabTextHorizontalPadding="16dp"
            app:stl_defaultTabTextMinWidth="40dp"
            app:stl_defaultTabTextSize="12sp"
            app:stl_distributeEvenly="false"
            app:stl_dividerColor="@android:color/transparent"
            app:stl_dividerThickness="1dp"
            app:stl_drawDecorationAfterTab="true"
            app:stl_indicatorColor="@color/colorHighlight"
            app:stl_indicatorCornerRadius="2dp"
            app:stl_indicatorGravity="bottom"
            app:stl_indicatorInFront="false"
            app:stl_indicatorInterpolation="smart"
            app:stl_indicatorThickness="3dp"
            app:stl_indicatorWithoutPadding="false"
            app:stl_overlineColor="@android:color/transparent"
            app:stl_overlineThickness="0dp"
            app:stl_titleOffset="auto_center"
            app:stl_underlineColor="@android:color/transparent"
            app:stl_underlineThickness="1dp" />

        <android.support.v4.view.ViewPager
            android:id="@+id/fragment_home_viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

</ScrollView>

@pchauhan
Copy link

pchauhan commented Jun 8, 2016

I am facing same issue @NhenDen Did you got any soluction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants