How to make a smooth image rotation in Android?

I’m using a RotateAnimation to rotate an image that I’m using as a custom cyclical spinner in Android. Here’s my rotate_indefinitely.xml file, which I placed in res/anim/: <?xml version=”1.0″ encoding=”UTF-8″?> <rotate xmlns:android=”http://schemas.android.com/apk/res/android” android:fromDegrees=”0″ android:toDegrees=”360″ android:pivotX=”50%” android:pivotY=”50%” android:repeatCount=”infinite” android:duration=”1200″ /> When I apply this to my ImageView using AndroidUtils.loadAnimation(), it works great! spinner.startAnimation( AnimationUtils.loadAnimation(activity, R.anim.rotate_indefinitely) ); … Read more

Replace Fragment inside a ViewPager

I’m trying to use Fragment with a ViewPager using the FragmentPagerAdapter. What I’m looking for to achieve is to replace a fragment, positioned on the first page of the ViewPager, with another one. The pager is composed of two pages. The first one is the FirstPagerFragment, the second one is the SecondPagerFragment. Clicking on a … Read more

Set margins in a LinearLayout programmatically

I’m trying to use Java (not XML) to create a LinearLayout with buttons that fill the screen, and have margins. Here is code that works without margins: LinearLayout buttonsView = new LinearLayout(this); buttonsView.setOrientation(LinearLayout.VERTICAL); for (int r = 0; r < 6; ++r) { Button btn = new Button(this); btn.setText(“A”); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT); … Read more