代碼實(shí)現(xiàn)后界面如圖:
創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作與策劃設(shè)計(jì),尉犁網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十載,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:尉犁等地區(qū)。尉犁做網(wǎng)站價(jià)格咨詢:028-86922220一。xml文件
1.
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/relativelayout">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="當(dāng)前時(shí)間:"
android:textSize="16dp" />
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/text1"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="5dp" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/text1"
android:text="----------"
android:textSize="16dp" />
(注text是當(dāng)前時(shí)間顯示,不用管,直接一個(gè)GridView即可)
2.每個(gè)圖標(biāo)的xml
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:scaleType="fitXY"
android:layout_gravity="center"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"/>
二。界面很簡(jiǎn)單,下面是MainAcyivity代碼:
1.public class MainActivity extends Activity {
GridView gridview;
PictureAdapter adapter;
public static int colorcolor=Color.WHITE;
int[] p_w_picpaths=new int[]{R.drawable.newdate,R.drawable.beiwang,R.drawable.newout,R.drawable.newin,R.drawable.alldate,R.drawable.allbeiwang,R.drawable.allout,R.drawable.allin,R.drawable.personmanager,R.drawable.game,R.drawable.chat,R.drawable.relax,R.drawable.seeitlogo,R.drawable.aboutflag,R.drawable.settings,R.drawable.out};
String[] titles=new String[]{"寫日記","寫備忘","新增支出","新增收入","我的日記","我的備忘","總支出","總收入","個(gè)人管理","游戲娛樂(lè)","聊天室","最簡(jiǎn)瀏覽器","待開發(fā)。。。","關(guān)于我","系統(tǒng)設(shè)置","退出"};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridview=(GridView)findViewById(R.id.gv1);
adapter=new PictureAdapter(titles,p_w_picpaths,this);
gridview.setAdapter(adapter);
gridview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, View arg1, int arg2,
long arg3) {
Intent intent=null;
switch(arg2){
case 0:intent=new Intent(MainActivity.this,newDate.class);
startActivity(intent);
finish();
break;
case 1:intent=new Intent(MainActivity.this,newMark.class);
startActivity(intent);
finish();
break;
case 2:intent=new Intent(MainActivity.this,newOut.class);
startActivity(intent);
finish();
break;
case 3:intent=new Intent(MainActivity.this,newIn.class);
startActivity(intent);
finish();
break;
case 4:intent=new Intent(MainActivity.this,allDate.class);
startActivity(intent);
finish();
break;
case 5:intent=new Intent(MainActivity.this,allMark.class);
startActivity(intent);
finish();break;
case 6:intent=new Intent(MainActivity.this,allOut.class);
startActivity(intent);
finish();
break;
case 7:intent=new Intent(MainActivity.this,allIn.class);
startActivity(intent);
finish();
break;
case 8:intent=new Intent(MainActivity.this,PersonManager.class);
startActivity(intent);
finish();
break;
case 9:intent=new Intent(MainActivity.this,Game.class);
startActivity(intent);
finish();
break;
case 10:intent=new Intent(MainActivity.this,Chat.class);
startActivity(intent);
finish();
break;
case 11:intent=new Intent(MainActivity.this,WebGo.class);
startActivity(intent);
finish();
break;
case 12:intent=new Intent(MainActivity.this,TabsFrame.class);
startActivity(intent);
finish();
break;
case 13:intent=new Intent(MainActivity.this,Aboutauthor.class);
startActivity(intent);
finish();
break;
case 14:MainActivity.this.openOptionsMenu();
break;
case 15:showdialog(MainActivity.this);
break;
}
}
});
}
2.PictureAdapter類來(lái)自BaseAdapter自己寫:
package com.example.licaizhuanjia;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class PictureAdapter extends BaseAdapter {
private List
3.Picture類
package com.example.licaizhuanjia;
public class Picture {
private String title;
private int p_w_picpath;
public Picture(){
super();
}
public Picture(String title,int p_w_picpath){
super();
this.title=title;
this.p_w_picpath=p_w_picpath;
}
public void setImage(int p_w_picpath){
this.p_w_picpath=p_w_picpath;
}
public void setTitle(String title){
this.title=title;
}
public int getImage(){
return p_w_picpath;
}
public String getTitle(){
return title;
}
}
4.ViewHolder類
package com.example.licaizhuanjia;
import android.widget.ImageView;
import android.widget.TextView;
public class ViewHolder {
public TextView title;
public ImageView p_w_picpath;
}
(ps:可以吧picture類和ViewHolder類寫進(jìn)PictureAdapter類,一樣的效果)
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。