更新导航栏及首页制作

master
liu 2 years ago
parent 819b66e4db
commit 07ee79198d

@ -69,7 +69,7 @@
</profile-state> </profile-state>
</entry> </entry>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

@ -3,24 +3,38 @@ package com.orangesale.cn.activity;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentTransaction;
import com.orangesale.cn.R; import com.orangesale.cn.R;
import android.view.View; import android.view.View;
import com.orangesale.cn.fragment.IndexFragment; import com.orangesale.cn.fragment.IndexFragment;
import com.orangesale.cn.fragment.PersonFragment; import com.orangesale.cn.fragment.PersonFragment;
import com.orangesale.cn.fragment.ProductFragment; import com.orangesale.cn.fragment.ProductFragment;
import com.orangesale.cn.fragment.ShoppingFragment; import com.orangesale.cn.fragment.ShoppingFragment;
public class IndexActivity extends Activity implements ViewTreeObserver.OnDrawListener {
private IndexFragment indexFragment; public class IndexActivity extends Activity implements View.OnClickListener {
private ProductFragment productFragment; private ProductFragment productFragment;
private ShoppingFragment shoppingFragment; private ShoppingFragment shoppingFragment;
private IndexFragment indexFragment;
private PersonFragment personFragment; private PersonFragment personFragment;
private LinearLayout indexLine, productLine, shoppingLine, personLine; private LinearLayout indexLine;
private LinearLayout productLine;
private LinearLayout shoppingLine;
private LinearLayout personLine;
public IndexActivity(LinearLayout indexLine,LinearLayout productLine, LinearLayout shoppingLine, LinearLayout personLine) {
this.productLine = productLine;
this.personLine = personLine;
this.indexLine = indexLine;
this.shoppingLine = shoppingLine;
}
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -40,10 +54,8 @@ public class IndexActivity extends Activity implements ViewTreeObserver.OnDrawLi
indexLine = findViewById(R.id.content_cart); indexLine = findViewById(R.id.content_cart);
shoppingLine.setOnClickListener(this); shoppingLine.setOnClickListener(this);
indexLine = findViewById(R.id.content_person); indexLine = findViewById(R.id.content_pearson);
productLine.setOnClickListener(this); productLine.setOnClickListener(this);
} }
@Override @Override
@ -62,7 +74,7 @@ public class IndexActivity extends Activity implements ViewTreeObserver.OnDrawLi
initshoppingFragment(); initshoppingFragment();
break; break;
case R.id.content_person: case R.id.content_pearson:
//注册验证方法 //注册验证方法
initpersonFragment(); initpersonFragment();
break; break;
@ -70,51 +82,46 @@ public class IndexActivity extends Activity implements ViewTreeObserver.OnDrawLi
} }
private void initIndexFragment() { private void initpersonFragment() {
FragmentTransaction transaction = getFragmentManager().beginTransaction(); android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (indexFragment == null) {
indexFragment = new IndexFragment(); if (personFragment == null) {
transaction.replace(R.id.main_content, indexFragment); Intent intent = IndexActivity.this.getIntent();
transaction.commit(); Bundle bundle = intent.getExtras();
personFragment = new PersonFragment();
personFragment.setArguments(bundle);
} }
transaction.replace(R.id.main_content, personFragment);
transaction.commit();
}
private void initproductFragment() { private void initshoppingFragment() {
FragmentTransaction transaction = getFragmentManager().beginTransaction(); android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (productFragment == null) { if (shoppingFragment == null) {
productFragment = new ProductFragment(); shoppingFragment = new ShoppingFragment();
} }
transaction.replace(R.id.main_content, productFragment); transaction.replace(R.id.main_content, shoppingFragment);
transaction.commit(); transaction.commit();
} }
private void initshoppingCartFragment() {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (shoppingFragment == null) {
shoppingFragment = new ShoppingFragment();
}
transaction.replace(R.id.main_content, shoppingFragment);
transaction.commit();
}
private void initpersonFragment() {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (personFragment == null) {
Intent intent = IndexActivity.this.getIntent();
Bundle bundle = intent.getExtras();
personFragment = new PersonFragment();
personFragment.setArguments(bundle);
}
transaction.replace(R.id.main_content, personFragment);
transaction.commit();
}
}
@Override private void initproductFragment() {
public void onDraw() { android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (productFragment == null) {
productFragment = new ProductFragment();
}
transaction.replace(R.id.main_content, productFragment);
transaction.commit();
}
private void initIndexFragment() {
android.app.FragmentTransaction transaction = getFragmentManager().beginTransaction();
if (indexFragment == null) {
indexFragment = new IndexFragment();
}
transaction.replace(R.id.main_content,productFragment);
transaction.commit();
} }
} }

@ -0,0 +1,70 @@
package com.orangesale.cn.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.orangesale.cn.R;
import com.orangesale.cn.entity.Product;
import java.util.List;
public class ProductAdapter extends BaseAdapter {
private List<Product> productList;
private LayoutInflater layoutInflater;
public ProductAdapter(Context context, List<Product> productList) {
this.productList = productList;
this.layoutInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return productList.size();
}
@Override
public Object getItem(int position) {
return productList.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.categoty_detail_content, 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 = productList.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;
}
}

@ -1,6 +1,5 @@
package com.orangesale.cn.fragment; package com.orangesale.cn.fragment;
import android.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -8,34 +7,59 @@ import android.view.ViewGroup;
import android.widget.GridView; import android.widget.GridView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.SearchView; import android.widget.SearchView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.orangesale.cn.R; import com.orangesale.cn.R;
import com.orangesale.cn.adapter.Adapter;
import com.orangesale.cn.entity.Product; import com.orangesale.cn.entity.Product;
import com.orangesale.cn.adapter.ProductAdapter;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public abstract class IndexFragment extends Fragment implements View.OnClickListener { public class IndexFragment extends Fragment implements View.OnClickListener {
private SearchView searchView;
private LinearLayout bingtangchengLine;
private GridView gridView; private GridView gridView;
private Adapter adapter; private ProductAdapter productAdapter;
private List<Product> productList; private List<Product> productList;
private SearchView searchView;
private LinearLayout chuchengLine, qichengLine,bingtangchengLine;
@Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_index,container,false); View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_index, container, false);
init(view); init(view);
return view; return view;
} }
private void init(View view){
searchView = view.findViewById(R.id.searchView); private void init(View view) {
searchView = view.findViewById(R.id.searchview);
searchView.setOnClickListener(this); searchView.setOnClickListener(this);
chuchengLine= view.findViewById(R.id.chucheng);
chuchengLine.setOnClickListener(this);
qichengLine = view.findViewById(R.id.qicheng);
qichengLine.setOnClickListener(this);
bingtangchengLine = view.findViewById(R.id.bingtangcheng);
bingtangchengLine.setOnClickListener(this);
gridView = view.findViewById(R.id.index_famous_gridview);
initData(); initData();
adapter = new Adapter(getActivity(),productList); productAdapter = new ProductAdapter(getActivity(), productList);
gridView.setAdapter(adapter); gridView.setAdapter(productAdapter);
} }
@Override @Override
public void initData(){ public void onClick(View v) {
}
private void initData() {
productList = new ArrayList<>(); productList = new ArrayList<>();
Product product = new Product(); Product product = new Product();
product.setImageUrlId(R.drawable.bingtangcheng); product.setImageUrlId(R.drawable.bingtangcheng);
@ -51,7 +75,4 @@ public abstract class IndexFragment extends Fragment implements View.OnClickList
productList.add(product1); productList.add(product1);
} }
}
}

@ -67,4 +67,3 @@ public class PersonFragment extends Fragment implements View.OnClickListener {
} }
}

@ -17,7 +17,7 @@ public class ProductFragment extends Fragment {
@Nullable @Nullable
@Override @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); View view = LayoutInflater.from(getActivity()).inflate(R.layout.content_category, container, false);
return view; return view;
} }
} }

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#E8E8E8"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SearchView
android:id="@+id/searchview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/index_menu"
android:focusable="false"
android:iconifiedByDefault="false"
android:queryHint="请输入搜索内容" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:layout_marginTop="20dp"
android:layout_marginRight="1dp"
android:background="@drawable/index_menu"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/chucheng"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/chucheng"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="褚橙"
android:textColor="#696969"
android:textSize="20sp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/bingtangcheng"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bingtangcheng" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="冰糖橙"
android:textColor="#696969"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/qicheng"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/qicheng" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="脐橙"
android:textColor="#696969"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/juzi"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/juzi" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="tangerine"
android:textColor="#696969"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<include layout="@layout/index_hot"/>
</LinearLayout>

@ -0,0 +1,13 @@
<?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">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="product" />
</LinearLayout>

@ -0,0 +1,13 @@
<?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">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="shop" />
</LinearLayout>

@ -1,20 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" tools:context=".fragment.IndexFragment">
android:background="#E8E8E8">
<!-- TODO: Update blank fragment layout -->
<SearchView <TextView
android:id="@+id/searchView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:background="@drawable/index_menu" android:text="this is Index page" />
android:focusable="false"
android:iconifiedByDefault="false"
android:queryHint="请输入搜索内容"/>
/> </FrameLayout>
</LinearLayout>

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.PersonFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.ProductFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.ShoppingFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>

@ -0,0 +1,55 @@
<?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"
android:layout_marginTop="15dp">
<!--热门商品-->
<LinearLayout
android:id="@+id/index_famous_product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="#FFF"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:drawableLeft="@drawable/orange1"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:text="popular"
android:textColor="#000"
android:textSize="18sp" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center"
android:src="@drawable/arrow_right" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical">
<GridView
android:id="@+id/index_famous_gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E8E8E8"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="2" />
</LinearLayout>
</LinearLayout>
Loading…
Cancel
Save