第二天:
任务一:给某个屏幕设置淡入淡出效果
//进行淡入淡出的效果
initAnimation();
private void initAnimation() {
// TODO 自动生成的方法存根
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);//透明度
alphaAnimation.setDuration(3000);//设置时长
rl_root.startAnimation(alphaAnimation);
}
private void initUI() {
// TODO 自动生成的方法存根
tv_version_name = (TextView) findViewById(R.id.tv_version_name);
rl_root = (RelativeLayout) findViewById(R.id.rl_root);
}
<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"
android:background="@drawable/launcher_bg"
android:id="@+id/rl_root"
tools:context=".SplashActivity" >
ok,对项目的主题进行配置
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<!-- <TextView
android:text="功能列表"
android:gravity="center"
android:textSize="20sp"
android:textColor="#000"
android:padding="10dp"
android:background="#0f0"
android:layout_width="match_parent"
android:layout_height="wrap_content"/> -->
<style name="TitleStyle">
<item name="android:gravity">center</item>
<item name="android:textSize">20sp</item>
<item name="android:textColor">#000</item>
<item name="android:padding">10dp</item>
<item name="android:background">#0f0</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
</style>
<TextView
style="@style/TitleStyle"
android:text="功能列表" />
自定义类进行内容的聚焦,用于滚动
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class FocusTextView extends TextView {
//使用在通过java代码创建控件
public FocusTextView(Context context) {
super(context);
}
//由系统调用(带属性+上下文环境构造方法xml to java对象)
public FocusTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
//由系统调用(带属性+上下文环境构造方法+布局文件中定义样式文件构造方法xml)
public FocusTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
//这是第二种方法重写获取焦点的方法,由系统调用,调用的时候默认就能获取焦点,比textview好
@Override
public boolean isFocused() {
return true;
}
}
<com.example.moblesafe73.view.FocusTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:padding="5dp"
android:singleLine="true"
android:text="秋天秋天悄悄过去,留下小秘密,啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"
android:textColor="#000" >
</com.example.moblesafe73.view.FocusTextView>
开始着手设置九宫格
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<ImageView
android:id="@+id/iv_icon"
android:background="@drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_title"
android:text="模块标题"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<GridView
android:id="@+id/gv_home"
android:numColumns="3"
android:verticalSpacing="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</GridView>
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
public class HomeActivity extends Activity{
private String[] mTitleStrs;
private int[] mDrawableIds;
private GridView gv_home;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
initUI();
//初始化数据的方法
initData();
}
private void initData() {
//准备数据(文字(9组),图片(9张))
mTitleStrs = new String[]{
"手机防盗","通信卫士","软件管理","进程管理","流量统计","手机杀毒","缓存清理","高级工具","设置中心"
};
mDrawableIds = new int[]{
R.drawable.home_safe,R.drawable.home_callmsgsafe,
R.drawable.home_apps,R.drawable.home_taskmanager,
R.drawable.home_netmanager,R.drawable.home_trojan,
R.drawable.home_sysoptimize,R.drawable.home_tools,R.drawable.home_settings
};
//九宫格控件设置数据适配器(等同ListView数据适配器)
gv_home.setAdapter(new MyAdapter());
}
class MyAdapter extends BaseAdapter{
@Override
public int getCount() {
//条目的总数 文字组数 == 图片张数
return mTitleStrs.length;
}
@Override
public Object getItem(int position) {
return mTitleStrs[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = View.inflate(getApplicationContext(), R.layout.gridview_item, null);
TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
ImageView iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
tv_title.setText(mTitleStrs[position]);
iv_icon.setBackgroundResource(mDrawableIds[position]);
return view;
}
}
private void initUI() {
gv_home = (GridView) findViewById(R.id.gv_home);
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。