I'm having some problems mixing the old Google Nexus One with the new SupportMapFragment.
In a particular landscape view I have an HorizontalScrollView with a map and some info in a way you have to scroll in order to actually see the info.
The problem is that scrolling makes (somehow I can't understand right now) the SupportMapFragment's background visible (which seems to be black by default) while actually scrolling the whole view
Picture to show what I mean.
Altough not the same exact issue, there is a similar, reported bug, about it in gmaps-api-issues
So, what I've tested so far:
Setting the background to #color/transparent, even in XML and/or programatically.
Changing the SupportMapFragment z-ordering
Setting this code before calling my map:
GoogleMapOptions op = new GoogleMapOptions();
op.zOrderOnTop(true);
SupportMapFragment.newInstance(op);
So I ran out of ideas.
I've successfully tested same exact code in:
Galaxy Nexus
HTC Desire HD
Samsung Galaxy S3
Samsung Galaxy Mini
Galaxy Ace
EDIT: An interesting thing is, taking the screenshot made me realize that it was imposible to capture my specific case. When the screenshot was taken, the error only could be reproduced by changing to portrait and landscape again.
Any ideas? Did I missed anything obvious?
Thanks in advance for your comments.
I had a very similar issue but when i was adding the SlidingMenu library and i fixed it by using the hack on this comment
public class MyMapFragment extends SupportMapFragment() {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
setMapTransparent((ViewGroup) view);
return view;
};
private void setMapTransparent(ViewGroup group) {
int childCount = group.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = group.getChildAt(i);
if (child instanceof ViewGroup) {
setMapTransparent((ViewGroup) child);
} else if (child instanceof SurfaceView) {
child.setBackgroundColor(0x00000000);
}
}
}
Just to add to Robert Estivill's answer - it's probably best not to run the code on devices >= 4.1, as there is no problem with them.
Slightly modified version:
public class FixMapFragment extends SupportMapFragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
// Fix for black background on devices < 4.1
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN){
setMapTransparent((ViewGroup) view);
}
return view;
}
private void setMapTransparent(ViewGroup group) {
int childCount = group.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = group.getChildAt(i);
if (child instanceof ViewGroup) {
setMapTransparent((ViewGroup) child);
} else if (child instanceof SurfaceView) {
child.setBackgroundColor(0x00000000);
}
}
}
}
I would have put this in a comment, but I don't have enough rep
Related
I have updated my Sdk Oreo 8.0 When i come my current fragment to my previous fragment its crash because i am using if (view == null)
if i removed this condition it 'll work fine but have to load again view.
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
if (view == null) {
view = inflater.inflate(R.layout.home_fragement_layout, container, false);
ButterKnife.bind(this, view);
bundle=getArguments();
registrationResponse=(RegistrationResponse)bundle.getSerializable("registerresponse");
setadapter();
hitUserFavouriteOutfitsapi();
swipeRefreshLayout.setOnRefreshListener(this);
}
toolBarTopChangeState =((ToolBarTopChangeState)context);
toolBarTopChangeState.stateChangeToolBarIcon(0);
toolBarTopChangeState.stateChangeToolBarText(getString(R.string.app_name));
return view;
}
Use this code:
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.home_fragement_layout, container, false);
ButterKnife.bind(this, view);
bundle=getArguments();
registrationResponse=(RegistrationResponse)bundle.getSerializable("registerresponse");
setadapter();
hitUserFavouriteOutfitsapi();
swipeRefreshLayout.setOnRefreshListener(this);
toolBarTopChangeState =((ToolBarTopChangeState)context);
toolBarTopChangeState.stateChangeToolBarIcon(0);
toolBarTopChangeState.stateChangeToolBarText(getString(R.string.app_name));
return view;
}
On the lists is a good practice to check if the view is already created and if it's to use it further, but on the activities and fragments you should left the OS to decide when should inflate again the view. You can have a look over android lifecycle to understand better how it's works
it 'll happen because i am adding animation when fragment change and return to back.. This problem facing because of Android 8.0(Oreo) rest os working fine so I removed the animation during fragment change it 'll solved.
It is possible to get a list of all the currently displayed/on-screen android UI elements?
For example, if I have a app that look like this:
I would get a list that would contain:
TextView (Hello World!)
RelativeLayout (Or whatever the parent container is)
Etc if there were more elements
This would be great in the case I don't know the ID's, or even what UI elements will appear on screen, but I still want to hide/show them.
You can achieve this by using the following manager, nice and clean!
Use it anywhere you want and you'll get a list of the view and all its children.
(Needs to be done recursively)
LayoutManager.getViews(getWindow());
public class LayoutManager
{
private static List<View> views;
public static List<View> getViews(Window window) {
return getViews(window.getDecorView().getRootView(), true);
}
public static List<View> getViews(final View view, boolean starting)
{
if (starting) {
views = new ArrayList<>();
}
views.add(view);
/** Search in each ViewGroup children as well */
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
getViews(viewGroup.getChildAt(i), false);
}
}
return views;
}
}
Is there a way for Android Studio to show how many views that are present within an XML layout? As we all know, layouts should contain <=80 views hence any more than that then this warning appears therefore it would be very helpful to be told the amount.
LayoutName.xml has more than 80 views, bad for performance
public class FragmentApple extends android.support.v4.app.Fragment {
public FragmentApple () {
}
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_apple,container,false);
int num = FragmentApple.getChildCount(); Log.d("Number of views in layout: ", "" + num);
return v;
}
}
Have you tried this?:
layout.getChildCount();
UPDATE
after what we discussed in the comments, this is what you should do within your code:
public class FragmentApple extends android.support.v4.app.Fragment {
public FragmentApple () {
}
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_apple,container,false);
return v;
}
#Override
public void onStart(){
super.onStart()
RelativeLayout (or Linear as in your xml) rl = (RelativeLayout) v.findViewbyId(R.id.your_layout_id)
int num = rl.getChildCount();
Log.d("Number of views in layout: ", "" + num);
}
}
for new comers to this question, you could use the view hierarchy from android studio's android device monitor:
open the app from your device or an emulator, and browse to the view that you want to inspect
1- from the Studio's Menu bar open
tools -> Android -> Android device monitor
2- from Android device monitor Menu bar open
window -> open perspective -> Hierarchy view
it may load for some time.
if you want to learn more: https://developer.android.com/studio/profile/hierarchy-viewer.html
I have come across a problem where the screen of my Android device(Moto G2) gets blurred on click of a specific button in my app. This event happens occasionally and not everytime I click this button.
This scenario is not happening on few other devices (like LG G3) in which I have tested the app for some time.
I couldnot find anything related or useful in the Logs either.
Just to add, the Log in button which is posing this issue is in a view of a fragment attached.
A screenshot of the scenario :
Adding code in the Activity's onCreate() where it adds the Fragments :
if (savedInstanceState == null) {
facebookLoginBtnFragment = new FacebookLoginBtnFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.container, facebookLoginBtnFragment).commit();
googleLoginBtnFragment = new GoogleLoginBtnFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.container2, googleLoginBtnFragment).commit();
} else {
facebookLoginBtnFragment = (FacebookLoginBtnFragment)getSupportFragmentManager().findFragmentById(R.id.container);
googleLoginBtnFragment = (GoogleLoginBtnFragment)getSupportFragmentManager().findFragmentById(R.id.container2);
}
Below is the code of onCreateView() of the Google + fragment :
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_gplusloginbtns, container, false);
gplusButton = (SignInButton)rootView.findViewById(R.id.GPlus_Sign_in_button); gplusButton.setOnClickListener(this);
setGooglePlusButtonText(gplusButton, "Log in with Google");
rootView.findViewById(R.id.GPlus_sign_out_button).setOnClickListener(this);
if (mActivity.getClass().toString().contains("ShowProfile_act")) {
rootView.findViewById(R.id.GPlus_Sign_in_button).setVisibility(View.GONE);
} mConnectionProgressDialog = new ProgressDialog(getActivity()); mConnectionProgressDialog.setMessage("Logging in...");
return rootView;
}
Below is the code for setGooglePlusButtonText() method :
private void setGooglePlusButtonText(SignInButton signInButton, String buttonText) {
// Find the TextView that is inside of the SignInButton and set its text
for (int i = 0; i < signInButton.getChildCount(); i++) {
View v = signInButton.getChildAt(i);
if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setText(buttonText);
return;
}
}
}
-->The others methods of the fragment deal with connection maintenance part with the Google+ API.I assume they might not be relevant
Any suggestions, advices on the cause and how to avoid such scenarios would be helpful.
I've integrated a map fragment (Android Maps Api V2) in my app, and this works fine as shown in this pic :
but when soft keybord is shown, map is slided to top and becomes blank as shown in the following pic :
I also must say that this phenomenon accurs on a galaxy S (2.3.3) not in galaxy SIII and even not in galaxy Y, is it a performance problem or bug or am I missing anything ?
Please help if you ever have encountred this problem..
Thanks.
You could try this:
public class MyMapFragment extends SupportMapFragment() {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
setMapTransparent((ViewGroup) view);
return view;
};
private void setMapTransparent(ViewGroup group) {
int childCount = group.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = group.getChildAt(i);
if (child instanceof ViewGroup) {
setMapTransparent((ViewGroup) child);
} else if (child instanceof SurfaceView) {
child.setBackgroundColor(0x00000000);
}
}
}
// ...
};
Instead of using the mapFragment provided by google, use this one. It fixed the same issue for me, but it was doing it on a sliding menu.
Credits to: https://github.com/jfeinstein10/SlidingMenu/issues/168#issuecomment-11834105