How to use Percentage for android layout?

UPDATE 2018: PercentRelativeLayout and PercentFrameLayout are deprecated. Consider using ConstraintLayout Old Answer: So far Android Support library has limited on where to use this: with RelativeLayout android.support.percent.PercentRelativeLayout with FrameLayout android.support.percent.PercentFrameLayout How to use it? Well, first make sure to include the dependency at build.grade(Module: app) in your android app. dependencies { compile ‘com.android.support:percent:23.3.0’ } Then … Read more

How to programmatically round corners and set random background colors

Instead of setBackgroundColor, retrieve the background drawable and set its color: v.setBackgroundResource(R.drawable.tags_rounded_corners); GradientDrawable drawable = (GradientDrawable) v.getBackground(); if (i % 2 == 0) { drawable.setColor(Color.RED); } else { drawable.setColor(Color.BLUE); } Also, you can define the padding within your tags_rounded_corners.xml: <?xml version=”1.0″ encoding=”utf-8″?> <shape xmlns:android=”http://schemas.android.com/apk/res/android”> <corners android:radius=”4dp” /> <padding android:top=”2dp” android:left=”2dp” android:bottom=”2dp” android:right=”2dp” /> </shape>

Why does calling getWidth() on a View in onResume() return 0?

A view still hasn’t been drawn when onResume() is called, so its width and height are 0. You can “catch” when its size changes using OnGlobalLayoutListener(): yourView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // Removing layout listener to avoid multiple calls if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { yourView.getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { yourView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } populateData(); } }); … Read more

No resource identifier found for attribute ‘…’ in package ‘com.app….’

I just changed: xmlns:app=”http://schemas.android.com/apk/res-auto” to: xmlns:app=”http://schemas.android.com/apk/lib/com.app.chasebank” and it stopped generating the errors, com.app.chasebank is the name of the package. It should work according to this Stack Overflow : No resource identifier found for attribute ‘adSize’ in package ‘com.google.example’ main.xml

Android: why setVisibility(View.GONE); or setVisibility(View.INVISIBLE); do not work

I see quite a few things wrong. For starters, you don’t have your magic button defined and there is no event handler for it. Also you shouldn’t use: dp2.setVisibility(View.GONE); dp2.setVisibility(View.INVISIBLE); Use only one of the two. From Android documentation: View.GONE This view is invisible, and it doesn’t take any space for layout purposes. View.INVISIBLE This … Read more