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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With