This is my Layout where I add Tablayout and ViewPager inside the ScrollView .
EveryThing is ok , but viewPager fragment doesn't show anything .
This is My xml Layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#252525"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar">
<RelativeLayout
android:id="#+id/rel"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/poster"
android:layout_width="96dp"
android:layout_height="128dp"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
android:background="#eee"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txt_onvan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/poster"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="#id/poster"
android:text="عنوان" />
<TextView
android:id="#+id/txt_sazande"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_onvan"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="#id/poster"
android:text="سازنده" />
<TextView
android:id="#+id/txt_nazar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_sazande"
android:layout_toLeftOf="#id/poster"
android:text="تعداد نظر" />
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="#id/poster" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tablayout"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And This is my ViewPager Adapter :
package ir.dink.cordinatorexample;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
public class PagerAdapter extends FragmentStatePagerAdapter {
//============================================ Constructor
public PagerAdapter(FragmentManager fm) {
super(fm);
}
//============================================ GetItem Method ()
#Override
public Fragment getItem(int position) {
Fragment frag = null;
switch (position) {
case 0:
frag = new FragmentOne();
break;
case 1:
frag = new FragmnentTwo();
break;
}
return frag;
}
//============================================= GetCount Method ()
#Override
public int getCount() {
return 2;
}
//============================================= GetPageTitle
#Override
public CharSequence getPageTitle(int position) {
String title = "";
switch (position) {
case 0:
title = "First";
break;
case 1:
title = "Second";
break;
}
return title;
}
}
And This is Screen Shot from That :
You should add android:fillViewport="true" to your ScrollView.
like This :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#252525"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolbar"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/rel"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/poster"
android:layout_width="96dp"
android:layout_height="128dp"
android:layout_alignParentRight="true"
android:layout_margin="8dp"
android:background="#eee"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/txt_onvan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/poster"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="#id/poster"
android:text="عنوان" />
<TextView
android:id="#+id/txt_sazande"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_onvan"
android:layout_marginBottom="8dp"
android:layout_toLeftOf="#id/poster"
android:text="سازنده" />
<TextView
android:id="#+id/txt_nazar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/txt_sazande"
android:layout_toLeftOf="#id/poster"
android:text="تعداد نظر" />
<android.support.design.widget.TabLayout
android:id="#+id/tablayout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="#id/poster" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tablayout"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
and You can see the this link too .
Related
i just want to replace a fragment by using this code:
fragmentManager.beginTransaction()
.replace(R.id.homepage_fragment_menu, fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
the fragment has recyclerview. but when i see the result of fragment, there's no shown of recyclerview. but when i checked in LayoutInspector, it's showed, but invisible like
this
And here's the code when set the adapter on RecyclerView
bookingHistoryProgressBar.setVisibility(View.GONE);
bookingHistoryList.setVisibility(View.VISIBLE);
adapterBookingHistoryList = new AdapterBookingHistoryList(this, bookingHistoryListModels);
bookingHistoryList.setAdapter(adapterBookingHistoryList);
Here's the layout code for RecyclerView and Adapter
XML Fragment Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/grey"
tools:context=".home.bookinghistorypage.BookingHistoryFragment"
android:gravity="center">
<android.support.v7.widget.RecyclerView
android:id="#+id/bookingHistory_listBooking"
android:background="#color/white_3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Adapter
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/booking_history_cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardCornerRadius="6dp"
app:cardElevation="6dp"
android:layout_marginTop="#dimen/margin_small"
android:layout_marginBottom="#dimen/margin_small"
app:cardUseCompatPadding="true">
<LinearLayout
android:background="#color/white"
android:paddingLeft="#dimen/padding_large"
android:paddingRight="#dimen/padding_large"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<helper.CustomFontMontserratBoldTextView
android:id="#+id/booking_history_name"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="3dp"
android:textColor="#color/black"
android:textSize="#dimen/text_medium"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_code"
android:gravity="end"
android:layout_marginTop="#dimen/margin_large"
android:layout_marginBottom="#dimen/margin_small"
android:textColor="#color/grey_2"
android:textSize="#dimen/text_medium"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<helper.CustomFontMontserratBoldTextView
android:id="#+id/booking_history_status"
android:background="#color/lightOrange"
android:textColor="#color/black"
android:textSize="#dimen/text_very_small"
android:paddingLeft="#dimen/padding_small"
android:paddingRight="#dimen/padding_small"
android:paddingTop="#dimen/padding_small"
android:paddingBottom="#dimen/padding_small"
android:layout_marginBottom="#dimen/padding_small"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_marginBottom="#dimen/padding_medium"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:src="#mipmap/ic_tanggal"
android:layout_width="20dp"
android:layout_height="20dp" />
<helper.CustomFontMontserratRegularTextView
android:visibility="gone"
android:id="#+id/booking_history_day_booked"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginLeft="#dimen/margin_small"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_actual_date"
android:layout_marginStart="#dimen/margin_small"
android:layout_marginLeft="#dimen/margin_small"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<helper.CustomFontMontserratMediumTextView
android:id="#+id/booking_history_time_booked"
android:layout_marginStart="#dimen/margin_medium"
android:layout_marginLeft="#dimen/margin_medium"
android:textColor="#color/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
XML Activity (Parent of Fragment)
<com.flipboard.bottomsheet.BottomSheetLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/bottomsheet"
android:background="#color/black_image_view">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar_layout"
android:layout_height="?android:attr/actionBarSize"
android:layout_width="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar_title_and_description"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/homepage_fragment_menu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/appbar_layout"
android:layout_above="#id/navigation"
/>
<include
android:id="#+id/navigation"
layout="#layout/element_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ProgressBar
android:id="#+id/homepage_progressBar"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:visibility="gone" />
</RelativeLayout>
</com.flipboard.bottomsheet.BottomSheetLayout>
AdapterJava
#NonNull
#Override
public BookingHistoryListViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.adapter_booking_history,parent,false);
context = parent.getContext();
return new BookingHistoryListViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final BookingHistoryListViewHolder holder, final int position) {
String data = GetDateUtils.convertEpochToDate(dataList.get(position).getActualDate());
if(dataList.get(position).getBookingStatus().equals("Completed") && dataList.get(position).getFlagRating().equals(false)){
Intent intent = new Intent(holder.itemView.getContext(), ProfessionalRatingActivity.class);
intent.putExtra("professionalId", dataList.get(position).getProfessionalId());
intent.putExtra("expertiseId", dataList.get(position).getExpertiseId());
intent.putExtra("professionalName",dataList.get(position).getProfessionalName());
holder.itemView.getContext().startActivity(intent);
}
if(dataList.get(position).getBookingStatus().equals("OnProcess")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.on_process));
}else if(dataList.get(position).getBookingStatus().equals("Cancel")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.cancelled));
}else if(dataList.get(position).getBookingStatus().equals("Completed")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.completed));
}else if(dataList.get(position).getBookingStatus().equals("Reserved")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.reserved));
}else if(dataList.get(position).getBookingStatus().equals("Reschedule")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.rescheduled));
}else if(dataList.get(position).getBookingStatus().equals("Confirmed")){
holder.bookingHistoryStatus.setBackgroundColor(ContextCompat.getColor(this.context,R.color.confirmed));
}
holder.bookingHistoryName.setText(dataList.get(position).getProfessionalName());
holder.bookingHistoryStatus.setText(dataList.get(position).getBookingStatus());
holder.bookingHistoryDayBooked.setText(dataList.get(position).getDayBooked());
holder.bookingHistoryCode.setText(String.format(Locale.getDefault(),"ID: %s",dataList.get(position).getCode()));
holder.bookingHistoryActualDate.setText(String.format(Locale.getDefault(),"%s",data));
holder.bookingHistoryTimeBooked.setText(String.format(Locale.getDefault(),"# %s",dataList.get(position).getTimeBooked()));
holder.bookingHistoryCardview.setOnClickListener(v -> {
Intent intent = new Intent(v.getContext(), BookingHistoryDetailActivity.class);
intent.putExtra("idProfessionalAdapter", dataList.get(position).getId());
holder.itemView.getContext().startActivity(intent);
});
}
#Override
public int getItemCount() {
return dataList!=null ? dataList.size() :0 ;
}
You're nesting your fragment view in a BottomSheetLayout, and according to the source code, the initial visibility is View.INVISIBLE:
private void init() {
// ...
dimView = new View(getContext()); // Line 150
dimView.setBackgroundColor(Color.BLACK);
dimView.setAlpha(0);
dimView.setVisibility(INVISIBLE);
// ...
}
public void setContentView(View contentView) {
super.addView(contentView, -1, generateDefaultLayoutParams());
super.addView(dimView, -1, generateDefaultLayoutParams());
}
I'm not familiar with Flipboard library, but I've got a feeling that you might be using it incorrectly. Maybe try:
bottomSheetLayout.showWithSheetView(...)
Or please check on their GitHub for usage.
Your recycler view in xml layout has `android:visibility="gone". Remove this line or change it to visible.
I have Fragment with layout of CoordinatorLayout Inside with NestedScrollView and inside nestedscrollview i have ViewPager and TabLayout with fragments. Tabs is visible but fragment related to tabs is not loading.
Layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:clickable="true"
android:background="?android:attr/colorBackground"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!--app:contentScrim="?attr/colorPrimary" -->
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ViewPagerImages"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7"
android:scrollIndicators="top|right">
</android.support.v4.view.ViewPager>
<ProgressBar
android:layout_width="120dp"
android:layout_height="120dp"
android:id="#+id/Progress_Bar_Image"
android:layout_gravity="center_horizontal|center_vertical"
android:visibility="visible"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="right|top"
android:layout_marginRight="30dp"
android:layout_marginTop="30dp"
android:background="#drawable/round_default"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="/5"/>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_gravity="bottom"
android:padding="15dp"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unsa"
android:orientation="horizontal"
android:gravity="center">
<ImageView
android:id="#+id/user_S"
android:layout_width="25dp"
android:layout_height="25dp"
android:padding="10dp" />
<TextView
android:id="#+id/ViewPager_Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
app:layout_behavior="com.boysjoys.com.pro_working1.CustomClass.UserProfile_Behaviour"
android:textSize="35sp" />
<TextView
android:id="#+id/ViewPager_A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Age"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="New Delhi"
android:layout_below="#id/unsa"
android:layout_marginLeft="37dp"
android:id="#+id/ViewPager_City"
/>
<Button
android:id="#+id/Attached"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:background="#drawable/round_button"
android:layout_alignParentBottom="true"
android:elevation="14dp"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:text="WRITE ME"
android:textColor="#FFFFFF"
android:textSize="20sp" />
</RelativeLayout>
<View
android:id="#+id/fabBGLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/custom_transparent_color1"
android:visibility="gone"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabOne"
android:layout_gravity="bottom|end"
android:padding="12dp"
android:visibility="gone"
android:layout_marginBottom="90dp"
android:layout_marginRight="20dp"
android:layout_width="45dp"
android:layout_height="45dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabTwo"
android:padding="12dp"
app:fabSize="mini"
android:visibility="gone"
android:layout_gravity="bottom|end"
android:layout_marginBottom="90dp"
android:layout_marginRight="20dp"
android:layout_width="45dp"
android:layout_height="45dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabThree"
android:layout_gravity="bottom|end"
android:padding="12dp"
app:fabSize="mini"
android:visibility="gone"
android:layout_marginBottom="90dp"
android:layout_marginRight="20dp"
android:layout_width="45dp"
android:layout_height="45dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabMain"
android:padding="12dp"
android:layout_gravity="bottom|end"
android:layout_marginBottom="90dp"
android:layout_marginRight="20dp"
android:src="#drawable/com_facebook_tooltip_black_xout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
// NESTED SCROLL VIEW WHERE THE PROBLEM ARISE
// TABLAYOUT IS VISIBLE BUT FRAGMENT IS NOT.
<android.support.v4.widget.NestedScrollView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/userProfile_NestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="13dp"
android:background="#android:color/white"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollViewChild"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="15dp">
<!--To show tab on top of view pager-->
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabTextColor="#color/place_autocomplete_prediction_primary_text_highlight"
app:tabSelectedTextColor="#color/colorPrimary"
app:tabIndicatorColor="#color/colorPrimary"
android:id="#+id/userProfile_Viewpager_Tab">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/userProfile_Viewpager_Tab"
android:id="#+id/userProfile_Viewpager_ViewPager">
</android.support.v4.view.ViewPager>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
ViewPager Adapter
public class UserProfile_TabAdapter extends FragmentPagerAdapter {
String TAG = "###TabAdapter###";
Context context;
public UserProfile_TabAdapter(FragmentManager fm,Context context) {
super(fm);
this.context=context;
}
#Override
public Fragment getItem(int position) {
Fragment fragment = null;
Log.d(TAG," Positions "+position);
switch (position) {
case 0:
fragment = Fragment.instantiate(context,Info_fragment.class.getName());
break;
case 1:
Log.d(TAG, "User Photos Running");
fragment = Fragment.instantiate(context,Photo_fragment.class.getName());
break;
case 2:
Log.d(TAG, "User Connections Running");
fragment = Fragment.instantiate(context,Connections_fragment.class.getName());
break;
}
return fragment;
}
#Override
public int getCount() {
return 3;
}
#Override
public CharSequence getPageTitle(int position) {
switch (position){
case 0:
return "About";
case 1:
return "Photo";
case 2:
return "Connections";
}
return null;
}
}
Fragment Where i try to load fragment into viewpager
//NESTED SCROLL VIEW TAB LAYOUT AND VIEW PAGER
userInfo_ViewPager=(ViewPager) view.findViewById(R.id.userProfile_Viewpager_ViewPager);
UserProfile_TabAdapter userProfile_tabAdapter=new UserProfile_TabAdapter(getChildFragmentManager(),getActivity());
userInfo_ViewPager.setAdapter(userProfile_tabAdapter);
tabLayout=(TabLayout) view.findViewById(R.id.userProfile_Viewpager_Tab);
tabLayout.setupWithViewPager(userInfo_ViewPager);
Fragment to load into viewpager
public class Info_fragment extends Fragment {
public static final String TAG="### INFO ####";
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.userprofile_photos,container,false);
//Above Layout only have colorful background to match parent.
return view;
}
}
Try this
NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.userProfile_NestedScrollView);
scrollView.setFillViewport (true);
Add This Line in your in NestedScrollView
android:fillViewport="true"
// your appBar layout height is match_parent change it with wrap_content
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
The problem is your view pager height. Just make some height then your page will be visible.
Example:
<android.support.v4.view.ViewPager
android:id="#+id/userProfile_Viewpager_ViewPager"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_below="#id/userProfile_Viewpager_Tab">
</android.support.v4.view.ViewPager>
You have to find the solution why the view pager not taken the height
or
NestedScrollView scrollView = (NestedScrollView) findViewById (R.id.userProfile_NestedScrollView);
scrollView.setFillViewport (true);
I have same issue and the best solution is to set hight for your viewpager
Example:
android:layout_height="500dp"
i try to show an ImageButton only when i swipe to one of my Fragments so if i swipe to a different Fragment the Visibillity should go to Invisible but i tried to do the following unfortunately it doesnt work the visibillity of my button is visible in all fragments.
I didnt find any Tutorial or something like that
Here is my Code i tried:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
switch (position) {
case 0:
firstfragment loc = new firstfragment();
settings.setVisibility(View.VISIBLE);
return loc;
case 1:
secondfragment qra = new secondfragment();
settings.setVisibility(View.INVISIBLE);
return qra;
case 2:
thirdfragment pre = new thirdfragment();
settings.setVisibility(View.INVISIBLE);
return pre;
default:
return null;
}
}
Here is my XML File:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.hartl.pxp.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<ImageButton
android:id="#+id/settingsbtn"
android:layout_width="20dp"
android:layout_height="match_parent"
android:background="#color/test"
android:foregroundGravity="center_vertical|center_horizontal"
android:scaleType="fitCenter"
android:src="#drawable/settings"
android:layout_marginRight="28dp"
android:layout_marginEnd="28dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:foregroundGravity="center_vertical|center_horizontal"
android:gravity="center_vertical|center_horizontal"
android:text="My App"
android:textColor="#color/white"
android:textSize="25sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
I am trying to create a layout like the below screenshot:
Below is the layout XML for the same:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context=".DetailActivity">
<android.support.design.widget.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/iv_movie_backdrop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/str_movie_backdrop_image"
android:scaleType="fitXY" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/cv_poster_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="#dimen/card_elevation"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true">
<ImageView
android:id="#+id/iv_movie_poster"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:contentDescription="#string/str_movie_poster"
android:padding="#dimen/poster_padding"
android:scaleType="fitXY"
android:src="#drawable/not_found" />
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="#id/cv_poster_image"
android:orientation="vertical">
<TextView
android:id="#+id/tv_movie_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="64dp"
android:layout_marginStart="8dp"
android:padding="#dimen/poster_padding"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="#android:color/black"
android:textStyle="bold"
tools:text="Spider Man and Iron Man" />
<TextView
android:id="#+id/tv_release_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:drawablePadding="#dimen/poster_padding"
android:drawableStart="#drawable/ic_date_range_black_24dp"
android:gravity="start"
android:padding="#dimen/poster_padding"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="#android:color/black"
tools:text="March, 2017" />
<TextView
android:id="#+id/tv_rating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:drawablePadding="#dimen/poster_padding"
android:drawableStart="#drawable/ic_star_black_24dp"
android:gravity="start"
android:padding="#dimen/poster_padding"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="#android:color/black"
tools:text="7.1" />
<TextView
android:id="#+id/tv_genre"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:padding="#dimen/poster_padding"
android:textAppearance="?android:textAppearanceSmall"
android:textColor="#android:color/black"
android:textStyle="italic"
tools:text="Horror | Comedy | Drama" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/cv_poster_image"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
style="#style/CategoryTab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabGravity="fill" />
<android.support.v4.view.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/fab_margin"
app:layout_anchor="#id/app_bar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="#drawable/ic_favorite_black_24dp" />
</android.support.design.widget.CoordinatorLayout>
My problem is the TabLayout with the ViewPager, I am not able to inflate the ViewPager with any FragmentLayout. If the same TabLayout and ViewPager I copy it to a new layout I am able to inflate the FragmentLayout and even the swipe works.
So is it because I can only have the TabLayout and the ViewPageralone in the activity and cannot have any other views on top of them.
Try adding android:fillViewport="true" to your NestedScrollView
in your Xml:
<android.support.v4.widget.NestedScrollView
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"
android:fillViewport="true" //add this
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"/> //change height to match parent
</android.support.v4.widget.NestedScrollView>
use this in your activity's oncreate()
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
and copy the below method and adapter to your activity
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new
ViewPagerAdapter(getSupportFragmentManager());
//change the fragmentName as per your need
adapter.addFragment(new FirstFragment(), "OVERVIEW");
adapter.addFragment(new Secondfragment(), "TRAILER");
adapter.addFragment(new thirdFragment(), "ORDERS");
viewPager.setAdapter(adapter);
}
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
#Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
#Override
public int getCount() {
return mFragmentList.size();
}
public void addFragment(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
#Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
I am making an app that has a ProfilePage with three fragments - About | Posts | Gallery, and I am using a collapsible toolbar with user's image. My second and third fragment will have a footer that should always be visible, but this is what I get:
When my image is expanded the footer disappears. What I want is for my two fragments to have these footers always visible and not depending on toolbar being collapsed or not. My gallery footer should be similar to post footer.
profile_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
contentScrim="?attr/colorPrimary"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/profile_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:contentDescription="#string/profile_photo"
app:layout_collapseMode="none"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
<ImageView
android:id="#+id/toolbarEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:contentDescription="#string/block"
android:paddingEnd="20dp"
android:paddingStart="5dp"
app:srcCompat="#drawable/ic_icon_edit" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.design.widget.TabLayout
android:id="#+id/myProfileTabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:tabContentStart="72dp"
app:tabGravity="fill"
app:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="#+id/myProfileViewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>
posts_fragment.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/tile_bg"
android:orientation="vertical" >
<ListView
android:id="#+id/list_view_messages"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#null"
android:divider="#null"
android:transcriptMode="alwaysScroll"
android:stackFromBottom="true">
</ListView>
<LinearLayout
android:id="#+id/llMsgCompose"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="horizontal"
android:weightSum="4" >
<EditText
android:id="#+id/inputMsg"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="3"
android:background="#color/bg_msg_input"
android:textColor="#color/text_msg_input"
android:paddingLeft="6dp"
android:paddingRight="6dp"/>
<Button
android:id="#+id/btnSend"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#color/ppdColorOrange"
android:textColor="#color/white"
android:text="#string/send" />
</LinearLayout>
My PostsFragment (not yet implemented):
public class MyProfilePostsFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.navdrawer_my_profile_fragment_posts, container, false);
return view;
}
}
I had the same requirement for my one of apps. I just did workaround.
Add your required layout in tab layout:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="256dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar"
android:layout_width="match_parent"
contentScrim="?attr/colorPrimary"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="#+id/profile_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:contentDescription="#string/profile_photo"
app:layout_collapseMode="none"/>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin">
<ImageView
android:id="#+id/toolbarEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:contentDescription="#string/block"
android:paddingEnd="20dp"
android:paddingStart="5dp"
app:srcCompat="#drawable/ic_icon_edit" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.design.widget.TabLayout
android:id="#+id/myProfileTabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:tabContentStart="72dp"
app:tabGravity="fill"
app:tabMode="scrollable" />
<android.support.v4.view.ViewPager
android:id="#+id/myProfileViewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</LinearLayout>
<-- Your required layout -->
<LinearLayout
android:id="#+id/tab123"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="4">
<EditText
android:id="#+id/inputMsg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:paddingLeft="6dp"
android:paddingRight="6dp" />
<Button
android:id="#+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="send" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Add following code in your Tab activity:
TabLayout tabLayout;
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);//add your viewpager to TabLayout
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
LinearLayout l=(LinearLayout) findViewById(R.id.tab123);
final EditText text=(EditText) findViewById(R.id.inputMsg);
Button send=(Button) findViewById(R.id.btnSend);
if (tab.getPosition() == 0) {
l.setVisibility(View.GONE);
System.out.println("About tab");
} else if (tab.getPosition() == 1) {
l.setVisibility(View.VISIBLE);
System.out.println("Posts tab");
send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String msg = null;
msg = text.getText().toString(); //get input
// Perform your desired task.
}
});
} else if (tab.getPosition() == 2) {
l.setVisibility(View.VISIBLE);
System.out.println("Gallery tab");
send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String msg = null;
msg = text.getText().toString(); //get input
//Perform your desired task.
}
});
}
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});