Here is how it looks like
I want to remove the distance between bottom of the ad and top of the bottom navigation view. I have no idea where is this gap comming from.
Here is my code:
MainActivity.java
private void initFragment() {
bottomNavigationView.post(() -> {
bottomNavViewHeight = bottomNavigationView.getMeasuredHeight();
FragmentList fragmentOne = new FragmentList();
Bundle args = new Bundle();
args.putInt("b_nav_height", bottomNavViewHeight);
fragmentOne.setArguments(args);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fragmentOne);
ft.commit();
});
}
FragmentList.java
private void initAd() {
AdView mAdView = getView().findViewById(R.id.adView);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mAdView.getLayoutParams();
Bundle bundle = getArguments();
if (bundle != null) {
numberOfCols = bundle.getString("number_of_cols", "null");
bottomNavHeight = bundle.getInt("b_nav_height", 0);
}
params.setMargins(0, 0, 0, bottomNavHeight); //substitute parameters for left, top, right, bottom
mAdView.setLayoutParams(params);
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView.loadAd(adRequest);
}
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="#+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/navigation"
android:animateLayoutChanges="true">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/myBackgroundColor"
app:menu="#menu/bottom_navigation_items"
app:labelVisibilityMode="selected"
app:itemTextAppearanceActive="#color/colorAccent"
app:itemTextColor="#color/bottom_nav_color"
app:itemIconTint="#color/bottom_nav_color"/>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout >
fragment_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/adView">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/card_view_recycler_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/adView" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
</RelativeLayout>
If you need something more just ask. If you need something more just ask. If you need something more just ask.
Related
Here is what I want.
The last item of recyclerview should be always above ad. Now it is partially hidden by an ad. App consists of main_layout where is FrameLayout with the name content_frame where fragment lies. Here is what I have written in code:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.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" />
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/app_bar_layout"
app:layout_constraintBottom_toTopOf="#id/bottomNavigation"
android:animateLayoutChanges="true"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorBottomNavigationViewBg"
app:itemIconTint="?attr/colorBottomNavigationViewItem"
app:itemTextAppearanceActive="#color/colorAccent"
app:itemTextColor="?attr/colorBottomNavigationViewItem"
app:labelVisibilityMode="selected"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/bottom_navigation_items" />
</androidx.constraintlayout.widget.ConstraintLayout >
fragment_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>
FragmentList.java
private void initAds(View view) {
RelativeLayout relativeLayout = view.findViewById(R.id.rl);
AdView adView = new AdView(view.getContext());
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layoutParams.addRule(RelativeLayout.BELOW, view.findViewById(R.id.recyclerview).getId());
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adView.setLayoutParams(layoutParams);
adView.setAdUnitId(BuildConfig.FLAVOR.equals("dev") ? AppConstants.TEST_BANNER_ID : AppConstants.FRAGMENT_LIST_BANNER_ID);
adView.setAdSize(AdSize.BANNER);
relativeLayout.addView(adView);
adView.setId(Util.getIdNotUsed(requireActivity()));
adView.loadAd(new AdRequest.Builder().build());
RecyclerView rv = view.findViewById(R.id.recyclerview);
RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
layoutParams2.addRule(RelativeLayout.ABOVE, adView.getId());
rv.setLayoutParams(layoutParams2);
}
So how can I make the last item of recycler view to be above ad? If there is anything you need more just tell me. Thank you.
You can add the adview and set its visibility to GONE when the ad is not displaying & make it visible while displaying the ad and constrain the recyclerview to its top.
I found a problem. I should have put SwipeRefreshLayout instead of RecyclerView rv = view.findViewById(R.id.recyclerview); to add ABOVE.
I'm attempting to create a simple image gallery with the thumbnails shown at the bottom using a RecyclerView and the large/detailed photo shown above it in an ImageView.
The problem is - the RecyclerView with the thumbnails is shown and created - however the large/detailed image is never shown, even when hardcoding it's background. I believe this to be an XML related issue - but I cannot seem to spot the problem.
Any suggestions are appreciated.
XML:
<?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:background="#color/black_color"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MMSGallery">
<ImageView
android:id="#+id/detail_photo"
android:background="#drawable/mms_img1"
android:adjustViewBounds="true"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:layout_margin="2dp"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_images"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/detail_photo"
android:background="#color/black_color" />
</RelativeLayout>
Java:
public class SpaceGalleryActivity extends AppCompatActivity {
ImageView mImageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_space_gallery);
mImageView = (ImageView) findViewById(R.id.detail_photo);
Glide.with(this)
.load("http://i.imgur.com/zuG2bGQ.jpg")
.placeholder(R.drawable.ic_launcher)
.into(mImageView);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this, 2);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rv_images);
recyclerView.setHasFixedSize(true);
// recyclerView.setLayoutManager(layoutManager);
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
SpaceGalleryActivity.ImageGalleryAdapter adapter = new SpaceGalleryActivity.ImageGalleryAdapter(this, SpacePhoto.getSpacePhotos());
recyclerView.setAdapter(adapter);
}
....
the problem is that you are setting RecyclerView to match_parent.which overlaps your ImageView
so change your layout to
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="#drawable/mms_img1"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="28dp"
android:id="#+id/rv_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/detail_photo"
android:layout_below="#id/detail_photo"
android:background="#color/black_color"
/>
</RelativeLayout>
It would work for you.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black">
<ImageView
android:id="#+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:adjustViewBounds="true"
android:background="#drawable/placeholder"
android:scaleType="centerCrop" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_images"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentBottom="true"
android:layout_below="#+id/detail_photo"
android:background="#color/red_500" />
<?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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MMSGallery">
<ImageView
android:id="#+id/detail_photo"
android:background="#mipmap/ic_launcher"
android:adjustViewBounds="true"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:layout_margin="2dp"
android:layout_width="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_images"
android:layout_below="#+id/detail_photo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/black_color" />
</RelativeLayout>
Changing from a RelativeLayout to a LinearLayout resolved the issue.
I want to add an image with a link inside a navigation drawer,
is it possible to add an image inside navigation drawer ?
I added coding like this but it is showing below error please check
ImageView imageView6 = (ImageView) findViewById(R.id.imageView6);
imageView6.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
specialOffers = (WebView) findViewById(R.id.specialOffers);
specialOffers.getSettings().setJavaScriptEnabled(true);
specialOffers.loadUrl("http://www.fbcdubai.com/membership/offres-privileges/");
}
});
}
open nav_header_layout_name.xml and add image view say (ProfileImage)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/nav_head"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:theme="#style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="#+id/home_profile_image"
android:layout_width="120dp"
android:layout_height="170dp"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:layout_gravity="center"
android:src="#drawable/profile_image"/>
</LinearLayout>
to access this image view from the java class:
- NavigationView navigationView = findViewById(R.id.nav_view_id);
- View hView = navigationView.getHeaderView(0);
- ImageView ProfileImage = (ImageViwe) hView.findViewById(R.id.home_profile_image);
create a listView inside the drawer navigation then create a custom item with image view finally attach it to a custom adapter
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="#layout/***"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/***"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/****"
android:id="#+id/nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="#+id/***"
android:layout_height="match_parent"
android:layout_width="match_parent"
/>
</LinearLayout>
</android.support.design.widget.NavigationView>
cust item
enter code here
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp"
android:background="#00000000">
<ImageView
android:id="#+id/****"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/****"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Certainly you can do this by setting a listener to your image inside the getView method of the adapter
discu.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//put here your code
});
I've been trying to replace the current fragment with another one when an item on the list view has been pressed. However when the button is pressed, the onClick method is fired but it does not replace the fragment.
JournalFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_journal_view, container, false);
context = getContext();
ListView myView = (ListView) rootView.findViewById(R.id.listView);
TableControllerUser TCU = new TableControllerUser(context);
final TableControllerJournal TCJ = new TableControllerJournal(context);
int accID = TCU.getLoggedInId();
Cursor cursor = TCJ.getAllJournals(accID);
Cursor allFood = TCJ.getAllFoodJournals(accID);
Cursor allActivity = TCJ.getAllActivityJournals(accID);
Cursor[] cursors = {cursor, allFood, allActivity};
MergeCursor m = new MergeCursor(cursors);
final JournalAdapter adapter = new JournalAdapter(context, m, 0);
myView.setAdapter(adapter);
myView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor c = (Cursor) adapter.getItem(position);
Toast.makeText(getActivity(), "onClick Pressed!", Toast.LENGTH_SHORT).show();
String title = c.getString(c.getColumnIndexOrThrow("title"));
if (title.contains("Glucose")) {
String glucose = c.getString(c.getColumnIndexOrThrow("glucose"));
String dateTime = c.getString(c.getColumnIndexOrThrow("glucose_time"));
String journalId = c.getString(c.getColumnIndexOrThrow("_id"));
String split[] = dateTime.split(" ");
String date = split[0];
String time = split[1];
Fragment gluFrag = new GlucoseFragment();
Bundle bundle = new Bundle();
bundle.putString("time", time);
bundle.putString("date", date);
bundle.putString("glucose", glucose);
bundle.putString("journalId", journalId);
gluFrag.setArguments(bundle);
((GraphActivity) getActivity()).replaceFragments(gluFrag, bundle);
}
}
});
return rootView;
// Inflate the layout for this fragment
}
}
JournalFragment.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"
tools:context="edu.tp.sghealthapp.JournalViewFragment"
android:id="#+id/jv">
<ListView
android:id="#+id/listView"
android:layout_below="#+id/viewPager"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#color/iron"
android:dividerHeight="1dp" />
</LinearLayout>
JournalListViewLayout.XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/txt_listTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/arrowIcon"
android:layout_toStartOf="#+id/arrowIcon"
android:textColor="#000000"
android:focusable="false"
android:textSize="16sp"
android:typeface="sans" />
<ImageView
android:id="#+id/arrowIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:focusable="false"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_arrow" />
</RelativeLayout>
GraphActivity.java
public class GraphActivity extends AppCompatActivity {
Context context;
TabLayout mTabLayout;
ViewPager mViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = getApplicationContext();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_graph);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setElevation(0);
mTabLayout = (TabLayout) findViewById(R.id.tabLayout);
mViewPager = (ViewPager) findViewById(R.id.viewPager);
ViewPagerAdapter pgAdapter = new ViewPagerAdapter(getSupportFragmentManager());
pgAdapter.addFragments(new GraphFragment(), "Graph");
pgAdapter.addFragments(new JournalViewFragment(), "Journal");
mViewPager.setAdapter(pgAdapter);
mTabLayout.setupWithViewPager(mViewPager);
}
public void replaceFragments(Fragment newFragment, Bundle bundle) {
Fragment fragment = newFragment;
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
fragment.setArguments(bundle);
ft.replace(R.id.jv, fragment);
ft.commit();
}
}
EDIT:
ActivityGraph.xml
<?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:orientation="horizontal"
tools:context=".GraphActivity"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/graph">
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primary"
app:tabGravity="fill"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/white"
app:tabTextColor="#color/black">
<!--To be fixed in future to occupy whole bar when mode = fixed-->
</android.support.design.widget.TabLayout>
<edu.tp.sghealthapp.library.graphViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tabLayout"></edu.tp.sghealthapp.library.graphViewPager>
</RelativeLayout>
EDIT 2
Tried Harron's and Vivek_Neel's methods, both of them work but cause this problem with the formatting
Putting android:layout_below="#+id/viewPager" in the linearLayout causes the fragment to no longer display
EDIT 3
Solved the formatting problem with this https://stackoverflow.com/a/34573034/5509513
activity_graph.xml :
<?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:orientation="horizontal"
tools:context=".GraphActivity"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/graph">
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primary"
app:tabGravity="fill"
app:tabMode="scrollable"
app:tabSelectedTextColor="#color/white"
app:tabTextColor="#color/black">
<!--To be fixed in future to occupy whole bar when mode = fixed-->
</android.support.design.widget.TabLayout>
<edu.tp.sghealthapp.library.graphViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/tabLayout"></edu.tp.sghealthapp.library.graphViewPager>
<LinearLayout
android:id="#+id/jv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<FrameLayout
android:id="#+id/jv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Put this code snip and into activity and check
Try wrap_content the height of View Pager and add Relative Layout with #+id/jd and give it layout below view pager.
Refer this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/graph"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/ColorPrimary"
app:tabGravity="fill"
app:tabMode="scrollable"
app:tabSelectedTextColor="#FFF"
app:tabTextColor="#000">
<!--To be fixed in future to occupy whole bar when mode = fixed-->
</android.support.design.widget.TabLayout>
<edu.tp.sghealthapp.library.graphViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tabLayout" />
<RelativeLayout
android:id="#+id/jv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/viewPager" />
</RelativeLayout>
EDIT 1
Second way to do it create new layout only with Frame Layout. And use it's Place Holder while replacing your Fragment.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/jd"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
I created one acivity and a few fragments. I try to show one of them after start-up but I see empty screen, without fragments (but with NavigationDrawer)
What do I do wrong?
I have no idea where my mistake is.
Thank you!
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportFragmentManager().beginTransaction()
.replace(R.id.content, new DashboardFragment()).commit();
...
public class DashboardFragment extends Fragment {
...
MainActivity.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
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"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"/>
</android.support.v4.widget.DrawerLayout>
Fragment:
<FrameLayout 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"
tools:context="com.romansytnyk.studentstudio.fragments.DashboardFragment">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/view">
<TextView
android:id="#+id/textView"
android:text="Week info \n\n"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
</FrameLayout>
first you should add fragment :
FragmentManager fm=getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.add([FRAGMENT],[STRING TAG]);
ft.commit();