android studio外卖界面页面代码
时间: 2023-09-20 10:10:21 浏览: 57
以下是一个简单的 Android Studio 外卖界面页面代码示例:
activity_main.xml:
```
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/restaurant_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@drawable/restaurant_image"/>
<TextView
android:id="@+id/restaurant_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/restaurant_image"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:text="Restaurant Name"
android:textColor="@color/black"
android:textSize="20sp"/>
<TextView
android:id="@+id/restaurant_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/restaurant_name"
android:layout_marginTop="8dp"
android:layout_marginStart="16dp"
android:text="Restaurant Address"
android:textColor="@color/grey"
android:textSize="16sp"/>
<TextView
android:id="@+id/restaurant_rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/restaurant_address"
android:layout_marginTop="8dp"
android:layout_marginStart="16dp"
android:text="4.5"
android:textColor="@color/black"
android:textSize="18sp"/>
<RatingBar
android:id="@+id/restaurant_rating_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/restaurant_address"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_toEndOf="@+id/restaurant_rating"
android:numStars="5"
android:rating="4.5"
android:stepSize="0.5"/>
<TextView
android:id="@+id/restaurant_delivery_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/restaurant_rating"
android:layout_marginTop="8dp"
android:layout_marginStart="16dp"
android:text="Delivery Time: 30 mins"
android:textColor="@color/grey"
android:textSize="16sp"/>
<TextView
android:id="@+id/restaurant_menu_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/restaurant_delivery_time"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:text="Menu"
android:textColor="@color/black"
android:textSize="20sp"/>
<ListView
android:id="@+id/restaurant_menu_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/restaurant_menu_title"
android:divider="@null"
android:dividerHeight="0dp"/>
</RelativeLayout>
```
MainActivity.java:
```
public class MainActivity extends AppCompatActivity {
private ImageView restaurantImage;
private TextView restaurantName;
private TextView restaurantAddress;
private TextView restaurantRating;
private RatingBar restaurantRatingBar;
private TextView restaurantDeliveryTime;
private TextView restaurantMenuTitle;
private ListView restaurantMenuList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
restaurantImage = findViewById(R.id.restaurant_image);
restaurantName = findViewById(R.id.restaurant_name);
restaurantAddress = findViewById(R.id.restaurant_address);
restaurantRating = findViewById(R.id.restaurant_rating);
restaurantRatingBar = findViewById(R.id.restaurant_rating_bar);
restaurantDeliveryTime = findViewById(R.id.restaurant_delivery_time);
restaurantMenuTitle = findViewById(R.id.restaurant_menu_title);
restaurantMenuList = findViewById(R.id.restaurant_menu_list);
// Set up the ListView with a simple adapter
String[] menuItems = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, menuItems);
restaurantMenuList.setAdapter(adapter);
}
}
```
注意:这只是一个简单的示例,实际的外卖应用程序可能需要更多的功能和布局。