您好,登錄后才能下訂單哦!
第二天:
任務一:給某個屏幕設置淡入淡出效果
//進行淡入淡出的效果
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。