android新手上路(二)--- 关于findViewById 返回为空

在oncreate中使用findViewById  时要将findViewById   放在setContentView()之后

因为当调用该函数之后才会绘制当前的layout,之前的layout成员都是不存在的,所以要将findViewById  的调用放在setContentView()之后


	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_other);
		tv = (TextView)Other.this.findViewById(R.id.text_other);
		if(tv != null){
			Intent it = getIntent();
			tv.setText(it.getStringExtra("enter") + ",终于出来了," + it.getStringExtra("mystring"));
		}

	}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
animation-list是Android中的一个Drawable资源类型,用于定义逐帧动画。它可以让你定义一系列不同的Drawable资源,并通过设置每个Drawable资源在动画中的时长和顺序来创建一个动画序列。每个Drawable资源可以是一个静态图像、一个逐帧动画或一个过渡动画。你可以将animation-list应用于任何ViewViewGroup的背景,以创建动态的背景效果。 要使用animation-list,你需要在res/drawable文件夹下创建一个XML文件,并在其中定义Drawable资源。以下是一个简单的animation-list示例: ```xml <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> <item android:drawable="@drawable/frame1" android:duration="100" /> <item android:drawable="@drawable/frame2" android:duration="100" /> <item android:drawable="@drawable/frame3" android:duration="100" /> </animation-list> ``` 在这个例子中,我们定义了一个animation-list,其中包含三个Drawable资源:frame1、frame2和frame3。我们设置了每个Drawable资源在动画序列中的时长为100毫秒,并将oneshot属性设置为true,表示动画只会播放一次。要在代码中使用这个animation-list,可以通过以下方式: ```java ImageView imageView = findViewById(R.id.image_view); imageView.setBackgroundResource(R.drawable.my_animation); AnimationDrawable anim = (AnimationDrawable) imageView.getBackground(); anim.start(); ``` 在这个例子中,我们首先获取了一个ImageView,并将其背景设置为animation-list资源my_animation。然后我们获取ImageView的背景,并将其转换为AnimationDrawable对象。最后,我们调用start()方法开始动画。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值