双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

java编译没错,但是打开程序报错

sdadsahgh sdadsahgh 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

java代码如下
package com.example.changecolors;

import java.util.Timer;
import java.util.TimerTask;


import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

public class FrameLayoutTest extends Activity {
private int current = 0;
final int[] colors = new int[] { R.color.color1, R.color.color2,
R.color.color3, R.color.color4, R.color.color5, R.color.color6,
R.color.color7 };
final int[] names = new int[] { R.id.view1, R.id.view2, R.id.view3,
R.id.view4, R.id.view5, R.id.view6, R.id.view7 };
TextView view[] = new TextView[7];

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
for (int i = 0; i < 7; i++) {
view[i] = (TextView) findViewById(names[i]);
}
final Handler handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == 0x1122) {
for (int i = 0; i < 7 - current; i++) {
view[i].setBackgroundResource(colors[i + current]);
}
for (int i = 7 - current, j = 0; j < 7; i++, j++) {
view[i].setBackgroundResource(colors[j]);
}
}
super.handleMessage(msg);
}
};
new Timer().schedule(new TimerTask() {

@Override
public void run() {
// TODO Auto-generated method stub
current++;
if (current >= 6) {
current = 0;
}
Message m = new Message();
m.what = 0x1122;
handler.sendMessage(m);
}
}, 0, 100);
}
}
xml配置如下:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:height="50px"
android:width="210px" />

<TextView
android:id="@+id/view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#bb0000"
android:height="50px"
android:width="180px" />

<TextView
android:id="@+id/view3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#dd0000"
android:height="50px"
android:width="150px" />

<TextView
android:id="@+id/view4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#990000"
android:height="50px"
android:width="120px" />

<TextView
android:id="@+id/view5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#770000"
android:height="50px"
android:width="90px" />

<TextView
android:id="@+id/view6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#550000"
android:height="50px"
android:width="60px" />

<TextView
android:id="@+id/view7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#330000"
android:height="50px"
android:width="30px" />

</FrameLayout>
Manifest的如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.changecolors"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.changecolors.FrameLayoutTest"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
...全文

相关推荐

评论 12
收藏 已收藏
分享
返回顶部
sdadsahgh
Android 80,489 成员 91,371 内容