添加购物车样式

master
tangxi 2 years ago
parent 1dcfd455b5
commit 0bfc81689a

@ -68,7 +68,6 @@ public class IndexActivity extends Activity implements View.OnClickListener {
case R.id.content_pearson:
initpearsonFragment();
break;
}
}

@ -3,6 +3,7 @@ package com.example.Cat.activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
@ -54,18 +55,21 @@ public class UserActivity extends Activity implements View.OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.user_product:
Intent intent2 = new Intent(this, GoodsActivity.class);
startActivity(intent2);
break;
case R.id.user_setting:
Log.i("message", "onClick: 111112222222222211");
Intent intent3 = new Intent(this, UserMessageActivity.class);
intent3.putExtra("username",username);
Log.i("message", "onClick: 11111111111");
startActivity(intent3);
break;
case R.id.user_product:
Intent intent2 = new Intent(this, GoodsActivity.class);
startActivity(intent2);
break;
case R.id.exit:
Intent intent4 = new Intent(this, MainActivity.class);
startActivity(intent4);
break;
}
}
}

@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
@ -22,6 +23,7 @@ public class UserMessageActivity extends AppCompatActivity implements View.OnCli
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("boyhood12", "onCreate: ");
setContentView(R.layout.user_msg);
Intent intent3=getIntent();
if(intent3.hasExtra("username")){

@ -0,0 +1,70 @@
package com.example.Cat.adapter;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.Cat.R;
import com.example.Cat.entity.Product;
import java.util.List;
public class CartAdapter extends BaseAdapter {
private List<Product> cartList;
private LayoutInflater layoutInflater;
public CartAdapter(Context context, List<Product> productList) {
this.cartList = productList;
this.layoutInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return cartList.size();
}
@Override
public Object getItem(int position) {
return cartList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView == null) {
Log.i("aa", "getView: "+"aa");
convertView = layoutInflater.inflate(R.layout.cart_good, null);
viewHolder = new ViewHolder();
viewHolder.productImage = convertView.findViewById(R.id.category_product_image);
viewHolder.productName = convertView.findViewById(R.id.category_product_name);
viewHolder.productPrice = convertView.findViewById(R.id.category_product_price);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
Product product = cartList.get(position);
Log.i("product", "getView: "+product.toString());
if (product != null) {
viewHolder.productImage.setBackgroundResource(product.getImageUrlId());
viewHolder.productName.setText(product.getProductName());
viewHolder.productPrice.setText(String.valueOf(product.getProductPrice()));
}
return convertView;
}
class ViewHolder {
ImageView productImage;
TextView productName, productPrice;
}
}

@ -0,0 +1,4 @@
package com.example.Cat.entity;
public class CartGood {
}

@ -0,0 +1,23 @@
package com.example.Cat.fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.Cat.R;
class CartFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_cart, container, false);
}
}

@ -5,17 +5,46 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.Cat.R;
import com.example.Cat.adapter.ProductAdapter;
import com.example.Cat.entity.Product;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class ProductFragment extends Fragment {
private GridView gridView;
private ProductAdapter productAdapter;
private List<Product> productList;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
public View onCreateView(
@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_product, container, false);
init(view);
return view;
}
private void init(View view) {
// gridView = view.findViewById(R.id.cart_goods_gridview);
initData();
// productAdapter = new ProductAdapter(getActivity(), productList);
// gridView.setAdapter(productAdapter);
}
/**
*
*/
private void initData() {
}
}

@ -5,17 +5,83 @@ import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.example.Cat.R;
import com.example.Cat.adapter.CartAdapter;
import com.example.Cat.adapter.ProductAdapter;
import com.example.Cat.entity.Product;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class ShoppingCartFragment extends Fragment {
private GridView gridView;
private CartAdapter CartAdapter;
private List<Product> productList;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_shopping, container, false);
View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_cart, container, false);
init(view);
return view;
}
private void init(View view) {
gridView = view.findViewById(R.id.index_cart_gridview);
initData();
CartAdapter = new CartAdapter(getActivity(), productList);
gridView.setAdapter(CartAdapter);
}
private void initData() {
productList = new ArrayList<>();
Product product = new Product();
product.setImageUrlId(R.drawable.mlp);
product.setProductName("猫粮盆");
product.setProductPrice(new BigDecimal("9.9"));
Product product1 = new Product();
product1.setImageUrlId(R.drawable.ml);
product1.setProductName("猫粮");
product1.setProductPrice(new BigDecimal("29.9"));
Product product2 = new Product();
product2.setImageUrlId(R.drawable.mwj3);
product2.setProductName("玩具");
product2.setProductPrice(new BigDecimal("19.9"));
Product product3 = new Product();
product3.setImageUrlId(R.drawable.ml3);
product3.setProductName("美味猫粮");
product3.setProductPrice(new BigDecimal("19.9"));
Product product4 = new Product();
product4.setImageUrlId(R.drawable.ml2);
product4.setProductName("营养猫粮");
product4.setProductPrice(new BigDecimal("49.9"));
Product product5 = new Product();
product5.setImageUrlId(R.drawable.mwj);
product5.setProductName("玩具");
product5.setProductPrice(new BigDecimal("9.9"));
Product product6=new Product();
product6.setImageUrlId(R.drawable.mwj2);
product6.setProductName("玩具");
product6.setProductPrice(new BigDecimal("9.9"));
Product product7=new Product();
product7.setImageUrlId(R.drawable.xmw);
product7.setProductName("小型猫窝");
product7.setProductPrice(new BigDecimal("29.9"));
productList.add(product);
productList.add(product1);
productList.add(product2);
productList.add(product3);
productList.add(product4);
productList.add(product5);
productList.add(product6);
productList.add(product7);
}
}

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- 结算区域 -->
<RelativeLayout
android:id="@+id/bottom_layout"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#fafafa"
android:padding="6dp">
<TextView
android:id="@+id/total_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="总计0.00"
android:textColor="#333"
android:textSize="16sp"
android:textStyle="bold" />
<Button
android:id="@+id/checkout"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#f44336"
android:text="结算"
android:textColor="#fff" />
<Button
android:id="@+id/clear_cart"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_toLeftOf="@id/checkout"
android:layout_centerVertical="true"
android:background="#333"
android:text="清空购物车"
android:textColor="#fff" />
</RelativeLayout>
</LinearLayout>

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="139dp"
android:background="#ffffff"
android:orientation="horizontal">
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView
android:id="@+id/category_product_image"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="5dp"
tools:srcCompat="@tools:sample/avatars" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="6"
android:background="#1EFFFFFF"
android:orientation="vertical">
<TextView
android:id="@+id/category_product_name"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="20dp"
android:text="商品名称"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/category_product_price"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_marginLeft="20dp"
android:text="价格" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="650dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<GridView
android:id="@+id/index_cart_gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="10dp"
android:numColumns="1"
android:verticalSpacing="10dp" />
</LinearLayout>
<include layout="@layout/cart_buttonlayout" />
</LinearLayout>

@ -0,0 +1,3 @@
<resources>
<dimen name="text_margin">16dp</dimen>
</resources>

@ -1,3 +1,92 @@
<resources>
<string name="app_name">喵喵喵</string>
<string name="large_text">
"Material is the metaphor.\n\n"
"A material metaphor is the unifying theory of a rationalized space and a system of motion."
"The material is grounded in tactile reality, inspired by the study of paper and ink, yet "
"technologically advanced and open to imagination and magic.\n"
"Surfaces and edges of the material provide visual cues that are grounded in reality. The "
"use of familiar tactile attributes helps users quickly understand affordances. Yet the "
"flexibility of the material creates new affordances that supercede those in the physical "
"world, without breaking the rules of physics.\n"
"The fundamentals of light, surface, and movement are key to conveying how objects move, "
"interact, and exist in space and in relation to each other. Realistic lighting shows "
"seams, divides space, and indicates moving parts.\n\n"
"Bold, graphic, intentional.\n\n"
"The foundational elements of print based design typography, grids, space, scale, color, "
"and use of imagery guide visual treatments. These elements do far more than please the "
"eye. They create hierarchy, meaning, and focus. Deliberate color choices, edge to edge "
"imagery, large scale typography, and intentional white space create a bold and graphic "
"interface that immerse the user in the experience.\n"
"An emphasis on user actions makes core functionality immediately apparent and provides "
"waypoints for the user.\n\n"
"Motion provides meaning.\n\n"
"Motion respects and reinforces the user as the prime mover. Primary user actions are "
"inflection points that initiate motion, transforming the whole design.\n"
"All action takes place in a single environment. Objects are presented to the user without "
"breaking the continuity of experience even as they transform and reorganize.\n"
"Motion is meaningful and appropriate, serving to focus attention and maintain continuity. "
"Feedback is subtle yet clear. Transitions are efficient yet coherent.\n\n"
"3D world.\n\n"
"The material environment is a 3D space, which means all objects have x, y, and z "
"dimensions. The z-axis is perpendicularly aligned to the plane of the display, with the "
"positive z-axis extending towards the viewer. Every sheet of material occupies a single "
"position along the z-axis and has a standard 1dp thickness.\n"
"On the web, the z-axis is used for layering and not for perspective. The 3D world is "
"emulated by manipulating the y-axis.\n\n"
"Light and shadow.\n\n"
"Within the material environment, virtual lights illuminate the scene. Key lights create "
"directional shadows, while ambient light creates soft shadows from all angles.\n"
"Shadows in the material environment are cast by these two light sources. In Android "
"development, shadows occur when light sources are blocked by sheets of material at "
"various positions along the z-axis. On the web, shadows are depicted by manipulating the "
"y-axis only. The following example shows the card with a height of 6dp.\n\n"
"Resting elevation.\n\n"
"All material objects, regardless of size, have a resting elevation, or default elevation "
"that does not change. If an object changes elevation, it should return to its resting "
"elevation as soon as possible.\n\n"
"Component elevations.\n\n"
"The resting elevation for a component type is consistent across apps (e.g., FAB elevation "
"does not vary from 6dp in one app to 16dp in another app).\n"
"Components may have different resting elevations across platforms, depending on the depth "
"of the environment (e.g., TV has a greater depth than mobile or desktop).\n\n"
"Responsive elevation and dynamic elevation offsets.\n\n"
"Some component types have responsive elevation, meaning they change elevation in response "
"to user input (e.g., normal, focused, and pressed) or system events. These elevation "
"changes are consistently implemented using dynamic elevation offsets.\n"
"Dynamic elevation offsets are the goal elevation that a component moves towards, relative "
"to the components resting state. They ensure that elevation changes are consistent "
"across actions and component types. For example, all components that lift on press have "
"the same elevation change relative to their resting elevation.\n"
"Once the input event is completed or cancelled, the component will return to its resting "
"elevation.\n\n"
"Avoiding elevation interference.\n\n"
"Components with responsive elevations may encounter other components as they move between "
"their resting elevations and dynamic elevation offsets. Because material cannot pass "
"through other material, components avoid interfering with one another any number of ways, "
"whether on a per component basis or using the entire app layout.\n"
"On a component level, components can move or be removed before they cause interference. "
"For example, a floating action button (FAB) can disappear or move off screen before a "
"user picks up a card, or it can move if a snackbar appears.\n"
"On the layout level, design your app layout to minimize opportunities for interference. "
"For example, position the FAB to one side of stream of a cards so the FAB wont interfere "
"when a user tries to pick up one of cards.\n\n"
</string>
</resources>

Loading…
Cancel
Save