Last active
August 29, 2015 14:03
-
-
Save litao0621/b57fb9733c26544bf909 to your computer and use it in GitHub Desktop.
footertab pointer anim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity" > | |
<RelativeLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_alignParentBottom="true" > | |
<RadioGroup | |
android:id="@+id/main_footer" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:background="@color/c2" | |
android:gravity="center_vertical" | |
android:orientation="horizontal" > | |
<RadioButton | |
android:id="@+id/tab1" | |
style="@style/main_footbar_radio" | |
android:text="TAB1" /> | |
<ImageView | |
style="@style/main_footbar_cutline" | |
android:src="@drawable/widget_bar_cut_off" /> | |
<RadioButton | |
android:id="@+id/tab2" | |
style="@style/main_footbar_radio" | |
android:text="TAB2" /> | |
<ImageView | |
style="@style/main_footbar_cutline" | |
android:src="@drawable/widget_bar_cut_off" /> | |
<RadioButton | |
android:id="@+id/tab3" | |
style="@style/main_footbar_radio" | |
android:text="TAB3" /> | |
<ImageView | |
style="@style/main_footbar_cutline" | |
android:src="@drawable/widget_bar_cut_off" /> | |
<RadioButton | |
android:id="@+id/tab4" | |
style="@style/main_footbar_radio" | |
android:text="TAB4" /> | |
</RadioGroup> | |
<TextView | |
android:id="@+id/pointer" | |
android:layout_width="wrap_content" | |
android:layout_height="5dp" | |
android:background="#000000" | |
/> | |
</RelativeLayout> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gitonway.footertab; | |
import android.app.Activity; | |
import android.graphics.Point; | |
import android.os.Bundle; | |
import android.view.Display; | |
import android.widget.RadioGroup; | |
import android.widget.RadioGroup.OnCheckedChangeListener; | |
import android.widget.TextView; | |
import com.nineoldandroids.animation.ObjectAnimator; | |
public class MainActivity extends Activity implements OnCheckedChangeListener{ | |
/** | |
* 指示器动画执行时间 | |
*/ | |
private final int DURATION=1 * 500; | |
/** | |
* TAB项个数 | |
*/ | |
private final int TAB_NUMBER=4; | |
private RadioGroup mRadioGroup; | |
private TextView mTextViewPointer; | |
/** | |
* 当前指示器X坐标 | |
*/ | |
private int currentX; | |
/** | |
* 屏幕宽度 | |
*/ | |
private int width; | |
/** | |
* 指示器宽度 | |
*/ | |
private int PointerWidth; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
init(); | |
} | |
private void init() { | |
Display display = getWindowManager().getDefaultDisplay(); | |
Point size = new Point(); | |
display.getSize(size); | |
width = size.x;//屏幕宽度 | |
PointerWidth=width/TAB_NUMBER; | |
mRadioGroup = (RadioGroup) findViewById(R.id.main_footer); | |
mTextViewPointer=(TextView) findViewById(R.id.pointer); | |
mRadioGroup.setOnCheckedChangeListener(this); | |
mTextViewPointer.setWidth(PointerWidth); | |
} | |
/** | |
* 移动指针位置 | |
* @param toLocation 要移动到的位置 | |
* @param checkedIndex 被选中TAB索引 | |
*/ | |
private void moveTo(int toLocation,int checkedIndex) | |
{ | |
ObjectAnimator.ofFloat(mTextViewPointer, "translationX", currentX, toLocation).setDuration(DURATION).start(); | |
currentX=PointerWidth*checkedIndex; | |
} | |
@Override | |
public void onCheckedChanged(RadioGroup group, int checkedId) { | |
switch (checkedId) { | |
case R.id.tab1: | |
moveTo(0*PointerWidth,0); | |
break; | |
case R.id.tab2: | |
moveTo(1*PointerWidth,1); | |
break; | |
case R.id.tab3: | |
moveTo(2*PointerWidth,2); | |
break; | |
case R.id.tab4: | |
moveTo(3*PointerWidth,3); | |
break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style name="footbar"> | |
<item name="android:layout_width">fill_parent</item> | |
<item name="android:layout_height">fill_parent</item> | |
<item name="android:layout_weight">1</item> | |
<item name="android:textSize">@dimen/text_size_10</item> | |
<item name="android:singleLine">true</item> | |
<item name="android:ellipsize">marquee</item> | |
<item name="android:gravity">center</item> | |
<item name="android:button">@null</item> | |
<item name="android:paddingTop">@dimen/space_1</item> | |
<item name="android:paddingBottom">@dimen/space_3</item> | |
</style> | |
<style name="main_footbar_radio" parent="footbar"> | |
<item name="android:background">@drawable/widget_bar_bg</item> | |
<item name="android:padding">0dip</item> | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment