自定义属性

//实现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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值