android个人中心页面代码
时间: 2023-09-09 12:08:25 浏览: 42
以下是一个简单的 Android 个人中心页面的代码示例:
XML 布局文件:
```
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp" >
<ImageView
android:id="@+id/profileImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/profile_image" />
<TextView
android:id="@+id/profileName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="8dp"
android:text="John Doe"
android:textSize="24sp" />
</LinearLayout>
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/topLayout"
android:divider="@null"
android:dividerHeight="0dp" />
</RelativeLayout>
```
Java 代码:
```
public class ProfileActivity extends AppCompatActivity {
private ListView mListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
mListView = findViewById(R.id.listView);
// Create the list items
ArrayList<String> listItems = new ArrayList<>();
listItems.add("My Account");
listItems.add("My Orders");
listItems.add("My Wishlist");
listItems.add("Settings");
listItems.add("Logout");
// Create the adapter
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, listItems);
// Set the adapter
mListView.setAdapter(adapter);
}
}
```
这个示例中,我们使用了一个 `RelativeLayout` 布局来组织页面,其中包含了一个上半部分的 `LinearLayout`,用来显示头像和用户名,以及一个下半部分的 `ListView`,用来显示用户的各种操作选项。
在 `onCreate` 方法中,我们首先获取了 `ListView` 的引用,然后创建了一个包含了各种操作选项的 `ArrayList`,接着创建了一个 `ArrayAdapter`,并将其设置为 `ListView` 的适配器,以此来展示用户的操作选项。