//实现LinearLayout
public class zhuanpan extends LinearLayout {
private ProgressBar pro;
private TextView jindu;
public zhuanpan(Context context) {
this( context, null );
}
public zhuanpan(Context context, @Nullable AttributeSet attrs) {
this( context, attrs, 0 );
}
public zhuanpan(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super( context, attrs, defStyleAttr );
init( context );
}
private void init(Context context) {
View view = View.inflate( getContext(), R.layout.zhuanpan, this );
pro = view.findViewById( R.id.pro );
jindu= view.findViewById( R.id.jindu );
}
public void set(int num){
jindu.setText( num+"%" );
pro.setProgress( num);
}
//
//
//
/
/
/
//MainActitcy
public class MainActivity extends AppCompatActivity {
private TextView text;
private com.example.yuekaolianxi1.Custom.zhuanpan zhuanpan;
int i = 0;
private Handler mHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );
initView();
mHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
super.handleMessage( msg );
if (i<100){
i++;
zhuanpan.set( i );
send();
}
}
};
//属性动画
AnimatorSet set = new AnimatorSet();
ObjectAnimator oa = ObjectAnimator.ofFloat( text, "translationX", new float[]{10f, 20f, 30f, 40f, 60f, 80f} );
oa.setDuration( 4500 );
ObjectAnimator oa2 = ObjectAnimator.ofFloat( text, "scaleX", new float[]{1f, 2f, 3f, 4f, 5f, 6f} );
oa2.setDuration( 4500 );
set.playTogether( oa, oa2 );
set.start();
set.addListener( new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
Intent intent = new Intent( MainActivity.this, MainActivity1.class );
startActivity( intent );
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
} );
}
private void send() {
mHandler.sendEmptyMessageDelayed( 1,25 );
}
private void initView() {
text = (TextView) findViewById( R.id.text );
zhuanpan = (zhuanpan) findViewById( R.id.zhuanpan );
}
@Override
protected void onResume() {
super.onResume();
send();
}
}
//
//
/
/
/
/
xml布局
RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=".MainActivity">
<TextView
android:id="@+id/text"
android:layout_width=“200dp”
android:layout_height=“60dp”
android:text=“八维哈哈”
android:textSize=“50dp”
/>
<com.example.yuekaolianxi1.Custom.zhuanpan
android:id="@+id/zhuanpan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></com.example.yuekaolianxi1.Custom.zhuanpan>
</LinearLayout>
/RelativeLayout>