请给出Android开发平台设计一个“家庭相册”软件的开发代码,其中登录界面有密码帐号文本框,登录注册按钮其中密码输入部分要求密码显示。登陆后的中心框架界面用选项卡的形式来设计,“家庭相册”的功能分为“家庭成员”、“大事记”和“相册”三大模块,要求如下: (1)标记为“家庭成员”的选项卡要求用ListView实现,用SimpleAdapter来帮助显示家庭成员的照片、姓名和生日等信息; (2)标记为“大事记”的选项卡要求用ListView实现,用ArrayAdapter来帮助显示重大事件的标题和时间等信息; (3)标记为“相册”的选项卡要求用九宫格实现,显示至少9张图片。
时间: 2024-02-15 12:04:42 浏览: 19
很高兴为您提供一个简单的Android开发平台“家庭相册”软件的开发代码,包括登录界面和中心框架界面。以下是您需要的代码:
1. 登录界面的 layout(login.xml):
```
<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">
<EditText
android:id="@+id/et_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:padding="10dp" />
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:padding="10dp" />
<Button
android:id="@+id/btn_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login" />
<TextView
android:id="@+id/tv_register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New user? Register here."
android:gravity="center"
android:textSize="14sp"
android:textStyle="bold"
android:padding="10dp" />
</LinearLayout>
```
2. 中心框架界面的 layout(main.xml):
```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv_family"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/lv_events"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<GridView
android:id="@+id/gv_album"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3" />
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
```
3. 登录界面的 Activity 代码:
```
public class LoginActivity extends AppCompatActivity {
private EditText etUsername, etPassword;
private Button btnLogin;
private TextView tvRegister;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
etUsername = findViewById(R.id.et_username);
etPassword = findViewById(R.id.et_password);
btnLogin = findViewById(R.id.btn_login);
tvRegister = findViewById(R.id.tv_register);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: 实现登录功能
}
});
tvRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO: 跳转到注册界面
}
});
}
}
```
4. 中心框架界面的 Activity 代码:
```
public class MainActivity extends AppCompatActivity {
private ListView lvFamily, lvEvents;
private GridView gvAlbum;
private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lvFamily = findViewById(R.id.lv_family);
lvEvents = findViewById(R.id.lv_events);
gvAlbum = findViewById(R.id.gv_album);
tabHost = findViewById(R.id.tabHost);
// 初始化 TabHost
tabHost.setup();
// 添加家庭成员选项卡
TabHost.TabSpec specFamily = tabHost.newTabSpec("Family").setIndicator("Family");
specFamily.setContent(new TabHost.TabContentFactory() {
@Override
public View createTabContent(String tag) {
return lvFamily;
}
});
tabHost.addTab(specFamily);
// 添加大事记选项卡
TabHost.TabSpec specEvents = tabHost.newTabSpec("Events").setIndicator("Events");
specEvents.setContent(new TabHost.TabContentFactory() {
@Override
public View createTabContent(String tag) {
return lvEvents;
}
});
tabHost.addTab(specEvents);
// 添加相册选项卡
TabHost.TabSpec specAlbum = tabHost.newTabSpec("Album").setIndicator("Album");
specAlbum.setContent(new TabHost.TabContentFactory() {
@Override
public View createTabContent(String tag) {
return gvAlbum;
}
});
tabHost.addTab(specAlbum);
// 初始化家庭成员 ListView
List<Map<String, Object>> familyList = new ArrayList<>();
familyList.add(new HashMap<String, Object>() {{
put("name", "John");
put("birthday", "1990-01-01");
put("photo", R.drawable.photo1);
}});
familyList.add(new HashMap<String, Object>() {{
put("name", "Mary");
put("birthday", "1992-03-15");
put("photo", R.drawable.photo2);
}});
SimpleAdapter familyAdapter = new SimpleAdapter(this, familyList, R.layout.family_item,
new String[]{"name", "birthday", "photo"},
new int[]{R.id.tv_name, R.id.tv_birthday, R.id.iv_photo});
lvFamily.setAdapter(familyAdapter);
// 初始化大事记 ListView
String[] events = {"Graduation Ceremony", "Wedding Anniversary", "Birthday Party", "New Year's Eve"};
ArrayAdapter<String> eventsAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, events);
lvEvents.setAdapter(eventsAdapter);
// 初始化相册 GridView
Integer[] photos = {R.drawable.photo3, R.drawable.photo4, R.drawable.photo5,
R.drawable.photo6, R.drawable.photo7, R.drawable.photo8, R.drawable.photo9,
R.drawable.photo10, R.drawable.photo11, R.drawable.photo12};
ArrayAdapter<Integer> albumAdapter = new ArrayAdapter<>(this, R.layout.album_item, photos);
gvAlbum.setAdapter(albumAdapter);
}
}
```
这个简单的“家庭相册”软件可以帮助您了解如何使用 ListView、GridView 和 TabHost 来构建一个功能完备的 Android 应用程序。当然,这只是一个基本的开发框架,您可以根据自己的需求进行更多的定制和改进。