Android 开发(五)主界面

一、从登陆界面进入之后,将进入主页面。

二、主页面是各个功能的列表,可以选择不同的功能进入。最上面是用户头像,点击可以进入用户设置。

activity_main.xml

1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 tools:context=".MainActivity" > 7 8 <ImageButton 9 android:id="@+id/ImageButton" 10 android:layout_width="wrap_content" 11 android:layout_height="wrap_content" 12 android:background="#00000000" 13 android:src="@drawable/header" 14 android:maxWidth="30dp" 15 android:maxHeight="30dp" 16 android:layout_gravity="center_horizontal"/> 17 <Button 18 android:id="@+id/SmileButton" 19 android:layout_width="match_parent" 20 android:layout_height="wrap_content" 21 android:text="@string/smile"/> 22 <Button 23 android:id="@+id/ThinkButton" 24 android:layout_width="match_parent" 25 android:layout_height="wrap_content" 26 android:text="@string/think"/> 27 <Button 28 android:id="@+id/DiscussButton" 29 android:layout_width="match_parent" 30 android:layout_height="wrap_content" 31 android:text="@string/discuss"/> 32 <Button 33 android:id="@+id/MusicButton" 34 android:layout_width="match_parent" 35 android:layout_height="wrap_content" 36 android:text="@string/music"/> 37 <Button 38 android:id="@+id/NoteButton" 39 android:layout_width="match_parent" 40 android:layout_height="wrap_content" 41 android:text="@string/note"/> 42 <Button 43 android:id="@+id/FriendButton" 44 android:layout_width="match_parent" 45 android:layout_height="wrap_content" 46 android:text="@string/friend"/> 47 48 </LinearLayout> 49

三、MainActivity.java

1 package com.diandianmi.activity; 2 3 import com.diandianmi.service.DataBaseService; 4 5 import android.os.Bundle; 6 import android.app.Activity; 7 import android.content.Intent; 8 import android.graphics.Bitmap; 9 import android.view.Menu; 10 import android.view.View; 11 import android.view.View.OnClickListener; 12 import android.widget.Button; 13 import android.widget.ImageButton; 14 import android.widget.ImageView; 15 16 public class MainActivity extends Activity { 17 18 private ImageButton imgShow; 19 20 String username = null; 21 @Override 22 protected void onCreate(Bundle savedInstanceState) { 23 super.onCreate(savedInstanceState); 24 setContentView(R.layout.activity_main); 25 imgShow = (ImageButton) this.findViewById(R.id.ImageButton); 26 imgShow.setAdjustViewBounds(true); //调整图片的大小 27 username = getIntent().getStringExtra("username"); 28 if(username!=null){ 29 DataBaseService dbSer = new DataBaseService(this); 30 Bitmap bit = dbSer.getIconByName(username); 31 if(bit!=null){ 32 imgShow.setImageBitmap(bit); 33 } 34 } 35 36 Button smileButton = (Button)findViewById(R.id.SmileButton); 37 Button thinkButton = (Button)findViewById(R.id.ThinkButton); 38 Button discussButton = (Button)findViewById(R.id.DiscussButton); 39 Button musicButton = (Button)findViewById(R.id.MusicButton); 40 Button noteButton = (Button)findViewById(R.id.NoteButton); 41 Button friendButton = (Button)findViewById(R.id.FriendButton); 42 43 44 45 OnClickListener clickListener = new OnClickListener(){ 46 Intent intent ; 47 48 @Override 49 public void onClick(View view) { 50 switch(view.getId()){ 51 case R.id.SmileButton: 52 intent = new Intent(MainActivity.this,SmileActivity.class); 53 startActivity(intent); 54 break; 55 case R.id.ThinkButton: 56 intent = new Intent(MainActivity.this,ThinkActivity.class); 57 startActivity(intent); 58 break; 59 case R.id.DiscussButton: 60 intent = new Intent(MainActivity.this,DiscussActivity.class); 61 startActivity(intent); 62 break; 63 case R.id.MusicButton: 64 intent = new Intent(MainActivity.this,MusicActivity.class); 65 startActivity(intent); 66 break; 67 case R.id.NoteButton: 68 intent = new Intent(MainActivity.this,NoteActivity.class); 69 startActivity(intent); 70 break; 71 case R.id.FriendButton: 72 intent = new Intent(MainActivity.this,FriendActivity.class); 73 startActivity(intent); 74 break; 75 case R.id.ImageButton: 76 intent = new Intent(MainActivity.this,UserActivity.class); 77 startActivity(intent); 78 break; 79 } 80 } 81 82 }; 83 84 smileButton.setOnClickListener(clickListener); 85 thinkButton.setOnClickListener(clickListener); 86 discussButton.setOnClickListener(clickListener); 87 musicButton.setOnClickListener(clickListener); 88 noteButton.setOnClickListener(clickListener); 89 friendButton.setOnClickListener(clickListener); 90 imgShow.setOnClickListener(clickListener); 91 92 } 93 94 95 96 @Override 97 public boolean onCreateOptionsMenu(Menu menu) { 98 // Inflate the menu; this adds items to the action bar if it is present. 99 getMenuInflater().inflate(R.menu.main, menu); 100 return true; 101 } 102 103 } 104

posted on 2013-09-22 21:04  songcser  阅读(597)  评论(0)    收藏  举报

导航