Anchored adaptive banners in LinearLayout structure - java

Good afternoon!
I am updating the normal(smart) admob banners for admob Anchored adaptive banners, I am following the example of google but I have several doubts.
I use LinearLayout as a general structure and not RelativeLayout like the google example.
When using the code to display the banner, it underlines two lines.
Example new code banner admob:
<FrameLayout
android:id="#+id/ad_view_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true" />
Yellow underline in android studios (in my code):
android:layout_centerInParent="true"
Message or warning:
Invalid layout param in a LinearLayout: layout_centerInParent
android:layout_alignParentBottom="true"
Message or warning:
Invalid layout param in a LinearLayout: layout_alignParentBottom
Example complet code banner google-admob:
https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/admob/AdaptiveBannerExample/app/src/main/res/layout/activity_my.xml
In the application the test ads are displayed well and work. But I don't like the messages of the underlined code (to avoid problems)
Before I used this code for my SMART banners:
<LinearLayout
android:id="#+id/ad_view_container"
android:orientation="vertical"
android:gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
Could I use the same code for Anchored adaptive banners? or does it have to be FrameLayout..?
thank you for answers

Try This
android:layout_gravity="center_horizontal|bottom"

Related

Cannot find added elements in Tabbed Activity

I created a Tabbed Activity template project using Android Studio.
Then I created a LinearLayout with a nested TextView on it:
<LinearLayout
android:id="#+id/updateView"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginTop="707dp"
android:orientation="vertical">
<TextView
android:id="#+id/updateTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:text="TextView" />
</LinearLayout>
This view is shown on preview, but there's none of it in the built app.
When I try to get a reference to it from my code:
LinearLayout lastUpdate = findViewById(R.id.updateView)
I get null in runtime.
So, how can I modify the code?
Preview screenshot
I solved my problem by moving xml code of LinearLayout upper, than code of AppBarLayout, and modification of dynamic pixels (dp) of ViewPager and my textView

Xml card layout

i trying to get a layout just like the image below for a game in android studio
currently my xml is
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="com.dreacot.testmymemory.Game">
<ImageView
android:id="#+id/imageView"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="136dp" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="156dp"
tools:layout_editor_absoluteY="136dp" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="266dp"
tools:layout_editor_absoluteY="136dp" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="53dp"
tools:layout_editor_absoluteY="285dp" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="156dp"
tools:layout_editor_absoluteY="285dp" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="72dp"
android:layout_height="115dp"
app:srcCompat="#drawable/backside"
tools:layout_editor_absoluteX="266dp"
tools:layout_editor_absoluteY="285dp" />
i want more cards to be added on the next level eg lvl 2
do i need to make several layouts for each level?
also i want each card to show its face when it is clicked
and finally i feel i am not doing the right thing as i feel xml files cannot be called into the gameplay is there a better way to do this layout(maybe programmatically)?
could anyone help?
The way you are doing it is not the proper way to do it, In this way maybe you can achieve this for 6 cards. What if you have let's say 100 cards or may be 1000, will you add 100 images in Layout and get reference of 100 images in Activity and set Click Listeners and animations to turn the side on 100 images?
Use "GridView" and Adapter for your views, it will do your work with ease.
Check this: https://developer.android.com/guide/topics/ui/layout/gridview.html
You have to do it programmatically.
1. Use RecyclerView with GridLayoutManager to show your card as grid style.
2. Create a layout with just a CardView with single ImageView for your single card item.
3. Create an custom RecyclerView.Adapter<> and use it with RecyclerView to populate your card data on CardView.
4. Add onItemClick listener to Adapter to flip to the specific Card item and do something as per your needs.
Here are some useful links about RecyclerView:
Android RecyclerView with GridLayoutManager Example
Android GridLayoutManager with RecyclerView in Material Design
Simple Android grid example using RecyclerView with GridLayoutManager
Here is a good library for CardView animation.
Hope this will help~

Picasso centerCrop and fit get different results

I want to insert an image to an ImageView, which gets used as a background. This background is in a RecyclerView. When it gets loaded the first time, it looks like this:
But when I scroll to another item and scroll back, it looks like this (it should always look like this):
Here i add the image:
public void onBindViewHolder(StoryViewHolder holder, int position) {
holder.cardView.setMinimumHeight(height/3);
holder.layout.setMinimumHeight((int) ((float) width / 4));
//set image
Picasso.with(activity).load(MainPostAdapter.URL + 140 + ".png").
transform(new BlurTransform(holder.background.getContext())).fit().centerCrop().into(holder.background);
holder.background.setAlpha(0.25f);
}
And this is the image itself:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/story_view_background"/>
What could the problem be?
EDIT:
whole XML (It doesn't show all of the code. Here is also pastebin:http://pastebin.com/8rJvSx7V):
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/story_view_background"/>
<RelativeLayout
android:id="#+id/story_view_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="50px">
<ImageView
android:id="#+id/story_view_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="#+id/story_view_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:layout_below="#+id/story_view_image"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</FrameLayout>
try to set android:layout_height="150dp" for your CardView (don't use px!). Its child FrameLayout is unnecesarry (CardView is extending FrameLayout and have set same attributes set), remove it.
It's not so well written, all your Views have match_parent set for height, besides Image and Text views... Your item is probably trying to fit RecyclerView height in this case ("whole screen") and is measured without image at first time (Picasso async downloading, setting image when view is already measured). But when you inflate your View again (scroll and recycle) new list item will be measured differently, because Picasso will insert your image "in runtime", no need to async fetching (cache)

Android Watch fullscreen FAB like the DismissOverlay

There is the DismissOverlayView, which you can implement to give the user an alternative way to exit the application on an android watch. This View implements something, that looks like a fullscreen FAB. Now I would like to know, how I could implement the same View with another button icon/color/behaviour. Since you can't change the DismissOverlayView which code looks btw. like this :
<android.support.wearable.view.DismissOverlayView
android:id="#+id/dismiss_overlay"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
I guess you have to implement some custom FAB, but I can't use the FAB in my watch XML either because there is an dependency missing or because it's simply not supported by the watch os. I tried following code for testing :
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_margin="16dp"
android:clickable="true"/>
Edit: For better understanding, I want the button look like this :
Edit: I just found this solution, I was not aware of that one :
https://developer.android.com/training/wearables/ui/confirm.html
But I would still be curious, if you could implement a more customisable version of this buttons.
Okay I found a solution for that problem, actually you can simply create a new layout.xml and overwrite the default code, which is the following one :
<merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="#+id/dismiss_overlay_explain"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="32dp"
android:layout_width="wrap_content"
android:padding="12dp"
style="#style/DismissOverlayText"
/>
<android.support.wearable.view.ActionPage
android:id="#+id/dismiss_overlay_button"
android:layout_height="match_parent"
android:background="#color/dismiss_overlay_bg"
android:layout_width="match_parent"
android:src="#drawable/ic_full_cancel"
android:color="#color/dismiss_close"
app:buttonRippleColor="#color/dismiss_close_pressed"
android:text="#string/dismiss_overlay_button_label"
/>
</merge>
Now you can use your newly created xml customise it and use this one instead of the original dimissOverlayView. But you should be careful with doing so, because this is not really intended from the design guidelines to do.

PreferenceFragment layout values

I'm creating an app with a main menu, one of these menu items will open up a PreferenceFragment. To create unity within the app I'd like the main menu to look as close to the PreferenceFragment as possible. Basically all the xml values I can use to create menu items that look similar to those in the PreferenceFragment.
Examples of values I need: text size and color (for both title and summary text) and padding values.
I could guess at it but that could take awhile and may not be accurate. There has to be a better way to do it.
Here is what I have so far:
Main Menu (the menu I want to look like the PreferenceFragment): http://i.imgur.com/O5jr14e.png
Preferences (the PreferenceFragment): http://i.imgur.com/YLUnNdX.png
Here are the layout values I have so far the menu item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="wrap_content" android:id="#+id/menu_item"
android:orientation="vertical" android:layout_weight="1"
android:paddingLeft="10dp">
<TextView android:id="#+id/menu_item_title"
android:textSize="20sp"
android:textColor="#android:color/white"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView android:id="#+id/menu_item_description"
android:textColor="#android:color/darker_gray"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
I am using a ListFragment with a custom ListAdapter to return the above layout with the required String values and display it in the list.
Thanks in advance!
You should use themes and styles if you are looking for the text size and color to be the same throughout the app.
http://developer.android.com/guide/topics/ui/themes.html

Categories