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.
Related
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.
I need help on how to remove the empty spaces between cardViews inside a Grid Layout. The empty space forms below each row of cards.I want to remove this extra space.How do i fix this.I have included a screenshot to clarify this.
Here is my code for my layout XML
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_below="#+id/toolbar"
android:layout_marginTop="50dp"
android:paddingBottom="0dp"
app:contentPaddingLeft="0dp"
app:contentPaddingRight="0dp"
app:contentPaddingTop="0dp"
app:cardUseCompatPadding="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:paddingTop="2dp"
android:id="#+id/text_view_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
android:textSize="11sp"
android:textAlignment="center" />
<ImageView
android:transitionName="#+id/profile"
android:layout_marginTop="10dp"
android:layout_below="#+id/text_view_name"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:id="#+id/image_view_upload"
android:adjustViewBounds="true"
android:clickable="false"
android:focusable="false"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
My MainActivity layout
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.RecyclerView
android:layout_marginTop="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/recycler_view"
android:background="#000000"
android:clipToPadding="false"/>
</RelativeLayout>
My java MainActivity class
public class MainActivity extends AppCompatActivity implements ImageAdapter.OnItemClickListener {
private RecyclerView recyclerview;
private ImageAdapter adapter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerview = (RecyclerView) findViewById(R.id.recycler_view);
adapter = new ImageAdapter(this, uploads);
recyclerview.setLayoutManager(new GridLayoutManager(this,3));
recyclerview.setPadding ( 1,1,1,1 );
}
}
Here is a Screenshot
Remove
android:layout_marginTop="50dp"
from your CardView
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_below="#+id/toolbar"
android:paddingBottom="0dp"
app:contentPaddingLeft="0dp"
app:contentPaddingRight="0dp"
app:contentPaddingTop="0dp"
app:cardUseCompatPadding="true"
android:orientation="vertical">
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 tried to use Dimezis's BlurView library to create a blur effect on android, but it hasn't worked at all.
I followed all the directions, but still it hasn't had any effect.
Here is the main activity layout that I inserted the BlurView layout xml into:
<?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/mainRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.mistplay.mistplay.MainActivity">
<eightbitlab.com.blurview.BlurView
android:id="#+id/blurView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:blurOverlayColor="#78ffffff">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<include layout="#layout/content_main" />
</eightbitlab.com.blurview.BlurView>
</android.support.design.widget.CoordinatorLayout>
And here is the code where I attempted to blur the screen in MainActivity:
#Override
protected void onResume() {
super.onResume();
updateBalanceandCheckTutorial();
if (UserManager.getInstance().getShouldShowTutorial()) {
BlurView blurView = (BlurView) findViewById(R.id.blurView);
final View decorView = getWindow().getDecorView();
final ViewGroup rootView = (ViewGroup) findViewById(R.id.mainRoot);
final Drawable windowBackground = decorView.getBackground();
blurView.setupWith(rootView)
.windowBackground(windowBackground)
.blurAlgorithm(new SupportRenderScriptBlur(this))
.blurRadius(10);
}
}
If anyone could tell me what I'm doing wrong that would be very helpful.
Thanks in advance!
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
});