京东APP(部分)-安卓
界面如下:(购物车,搜索界面略)
package com.example.jingdongtt; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.ListView; import android.widget.Toast; public class ClassifyActivity extends Fragment implements OnItemClickListener { ListView listView; ImageView iv; public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater.inflate(R.layout.aclassify, null); // 获取listview对象 listView = (ListView) view.findViewById(R.id.listView1); iv = (ImageView) view.findViewById(R.id.imageView1); // 准备数据源 String data[] = { "星空", "人物一", "人物二", "摩天轮" }; // 创建适配器 ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.item, data); // 给listview绑定适配器 listView.setAdapter(adapter); // 设置监听 listView.setOnItemClickListener(this); return view; } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getActivity(), "" + (position+1), Toast.LENGTH_SHORT).show(); switch (position) { case 0: iv.setImageResource(R.drawable.aa0); break; case 1: iv.setImageResource(R.drawable.aa1); break; case 2: iv.setImageResource(R.drawable.aa2); break; case 3: iv.setImageResource(R.drawable.aa3); break; default: break; } } }
package com.example.jingdongtt; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class HomeActivity extends Fragment { private View view; @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.ahome, null); return view; } }
package com.example.jingdongtt; import java.util.ArrayList; import java.util.Collection; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.ImageView; public class MainActivity extends FragmentActivity implements OnPageChangeListener, OnClickListener { private ViewPager viewPager; private ImageView iv_honme, iv_clasees, iv_shopcar, iv_serach, iv_user; private ImageView[] iv = { iv_honme, iv_clasees, iv_shopcar, iv_serach, iv_user }; private int ivID[] = { R.id.image_home, R.id.image_classes, R.id.image_shopcar, R.id.image_search, R.id.image_user }; private int iv_focus[] = { R.drawable.home_focus, R.drawable.classes_focus, R.drawable.car_focus, R.drawable.search_focus, R.drawable.user_focus}; private int iv_normal[] = { R.drawable.home_normal, R.drawable.classes_normal, R.drawable.car_normal, R.drawable.search_normal, R.drawable.user_normal}; private ArrayList<Fragment> fragment_list = new ArrayList<Fragment>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); init_ui(); init_viewPager(); } private void init_ui() { for (int i = 0; i < iv.length; i++) { iv[i] = (ImageView) findViewById(ivID[i]); iv[i].setOnClickListener(this); } } private void init_viewPager() { // 第一步,获取viewpager对象 viewPager = (ViewPager) findViewById(R.id.viewpager); // 第二步,将碎片对象添加到链表 //把界面加进来 fragment_list.add(new HomeActivity());//extends继承fragant了 fragment_list.add(new ClassifyActivity()); fragment_list.add(new ShoppingCartActivity()); fragment_list.add(new SearchActivity()); fragment_list.add(new User()); FragmentManager manager = getSupportFragmentManager(); FragmentStatePagerAdapter adapter = new FragmentStatePagerAdapter( manager) { @Override public int getCount() { // TODO Auto-generated method stub return fragment_list.size(); } @Override public Fragment getItem(int arg0) { // TODO Auto-generated method stub return fragment_list.get(arg0); } }; viewPager.setAdapter(adapter); viewPager.setOnPageChangeListener(this); } @Override public void onPageScrollStateChanged(int arg0) { } /** * 页面滚动中调用 */ @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // Log.d("tag", "2"); } /** * 切换完后调用 */ @Override public void onPageSelected(int arg0) { setImage(arg0); } /** * 导航图标监听 */ @Override public void onClick(View v) { int index = 0; switch (v.getId()) { case R.id.image_home: index = 0; break; case R.id.image_classes: index = 1; break; case R.id.image_shopcar: index = 2; break; case R.id.image_search: index = 3; break; case R.id.image_user: index = 4; break; default: break; } setImage(index); viewPager.setCurrentItem(index); } private void setImage(int index){ for (int i = 0; i < iv.length; i++) { if(index == i){ iv[i].setImageResource(iv_focus[index]); }else{ iv[i].setImageResource(iv_normal[i]); } } } }
package com.example.jingdongtt; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class SearchActivity extends Fragment { private View view; public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.asearch, null); return view; } }
package com.example.jingdongtt; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; public class ShoppingCartActivity extends Fragment { private View view; public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { view = inflater.inflate(R.layout.ashoppingcart, null); return view; } }
package com.example.jingdongtt; import android.app.Activity; import android.os.Bundle; public class turntomimaActivity extends Activity{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.turntomima); } }
package com.example.jingdongtt; import android.app.Activity; import android.os.Bundle; public class turntoregisterActivity extends Activity{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.turntoregist); } }
package com.example.jingdongtt; import android.content.Intent; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class User extends Fragment implements OnClickListener{ TextView text1,text2; Button denglu; @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater.inflate(R.layout.auser, null); //账户,输入密码 text1 = (TextView) view.findViewById(R.id.user_number); text2 = (TextView) view.findViewById(R.id.input_password); //点击登录按钮时,判断账号密码是否为空 denglu = (Button) view.findViewById(R.id.denglu_button); //连接跳转,用户注册,找回密码 TextView text5,text6; text5 = (TextView) view.findViewById(R.id.new_user_register); text6 = (TextView) view.findViewById(R.id.search_password); text5.setOnClickListener(this); text6.setOnClickListener(this); denglu.setOnClickListener(this); return view; } @Override public void onClick(View v) { // TODO Auto-generated method stub int id = v.getId(); Intent intent = new Intent(); //用户密码不嫩为空 String str1 = text1.getText().toString(); String str2 = text2.getText().toString(); int len1 = str1.length(); int len2 = str2.length(); switch (id) { //跳转 case R.id.new_user_register: intent.setClass(getActivity(), turntoregisterActivity.class); startActivity(intent); break; case R.id.search_password: intent.setClass(getActivity(), turntomimaActivity.class); startActivity(intent); break; case R.id.denglu_button: if(len1 > 0 && len2 > 0){ Toast.makeText(getActivity(), "登陆成功", Toast.LENGTH_SHORT).show(); }else{ Toast.makeText(getActivity(), "账号和密码不能为空", Toast.LENGTH_SHORT).show(); } break; default: break; } } }
item.xml(略);按照顺序如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <ListView android:id="@+id/listView1" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" > </ListView> <ImageView android:id="@+id/imageView1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" android:src="@drawable/classify" /> </LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="10" > </android.support.v4.view.ViewPager> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center_vertical" android:background="#ff000000" android:paddingTop="3dp" > <ImageView android:id="@+id/image_home" android:layout_width="0dp" android:layout_height="40dp" android:layout_weight="1" android:src="@drawable/home_focus" /> <ImageView android:id="@+id/image_classes" android:layout_width="0dp" android:layout_height="40dp" android:layout_weight="1" android:src="@drawable/classes_normal" /> <ImageView android:id="@+id/image_shopcar" android:layout_width="0dp" android:layout_height="40dp" android:layout_weight="1" android:src="@drawable/car_normal" /> <ImageView android:id="@+id/image_search" android:layout_width="0dp" android:layout_height="40dp" android:layout_weight="1" android:src="@drawable/search_normal" /> <ImageView android:id="@+id/image_user" android:layout_width="0dp" android:layout_height="40dp" android:layout_weight="1" android:src="@drawable/user_normal" /> </LinearLayout> </LinearLayout>
<?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" android:orientation="vertical" android:background="@drawable/shouye" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > </LinearLayout> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="首页" android:textSize="30dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="扫码" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:hint="搜索的历史记录" > <requestFocus /> </EditText> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="消息" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="推荐" android:textSize="30dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/imageView1" android:layout_width="100dp" android:layout_height="200dp" android:src="@drawable/xiaohua" /> <ImageView android:id="@+id/imageView2" android:layout_width="100dp" android:layout_height="200dp" android:src="@drawable/xinxingcao" android:paddingLeft="10dp" /> <ImageView android:id="@+id/imageView3" android:layout_width="100dp" android:layout_height="200dp" android:src="@drawable/aabb" android:paddingLeft="10dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="京东头条" android:textSize="30dp" /> <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="根据脸型选择发型" android:textSize="20dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="此兔非彼兔,潜水员发现毛茸茸的小海兔" android:layout_marginLeft="120dp" android:textSize="20dp"/> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="有刘海和没刘海是两个不同的世界" android:textSize="20dp" android:layout_marginLeft="120dp" /> </LinearLayout> </LinearLayout>
<?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" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="搜索" android:textSize="30dp" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:hint="请输入关键词" > <requestFocus /> </EditText> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > </LinearLayout> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="搜索" android:background="#ffff00ff" /> </LinearLayout>
<?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" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="购物车" android:textSize="30dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/aab" /> </LinearLayout> </LinearLayout>
<?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" android:orientation="vertical" android:background="@drawable/aac" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" android:textSize="30sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="100dp" android:text="账户" /> <EditText android:id="@+id/user_number" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:hint="请输入账户" android:layout_marginLeft="20dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码" /> <EditText android:id="@+id/input_password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="textPassword" android:hint="请输入密码" android:layout_marginLeft="20dp"> <requestFocus /> </EditText> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/denglu_button" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="登录" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/new_user_register" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="新用户注册" android:paddingRight="180dp" /> <TextView android:id="@+id/search_password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="找回密码" /> </LinearLayout> </LinearLayout>
<?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" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="修改密码" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="20dp" android:text="账号" /> <EditText android:id="@+id/editText4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:hint="用户名/邮箱/手机号" android:layout_marginLeft="50dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="20dp" android:text="新密码" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="textPassword" android:hint="6-16位字母/数字" android:layout_marginLeft="35dp" > <requestFocus /> </EditText> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="20dp" android:text="确认密码" /> <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="textPassword" android:hint="请再次输入密码" android:layout_marginLeft="20dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="20dp" android:text="电话" /> <EditText android:id="@+id/editText3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="phone" android:hint="请再次确认电话号码" android:layout_marginLeft="50dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffff0000" android:text="保存" /> </LinearLayout> </LinearLayout>
<?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" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="免费注册" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账号" /> <EditText android:id="@+id/editText3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:hint="用户名/邮箱/手机号" android:layout_marginLeft="50dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密码" android:paddingTop="20dp" /> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="textPassword" android:hint="6-16位字母/数字" android:layout_marginLeft="50dp" > <requestFocus /> </EditText> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView6" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确认密码" android:paddingTop="20dp" /> <EditText android:id="@+id/editText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="textPassword" android:hint="请再次输入密码" android:layout_marginLeft="20dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="电话" android:paddingTop="20dp" /> <EditText android:id="@+id/editText4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:ems="10" android:inputType="phone" android:hint="请输入电话号码" android:layout_marginLeft="50dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/textView8" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="20dp" android:text="头像" /> <ImageView android:id="@+id/imageView1" android:layout_width="80dp" android:layout_height="80dp" android:src="@drawable/touxiang" android:layout_marginLeft="200dp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffff0000" android:text="注册" /> </LinearLayout> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.jingdongtt" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="15" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="turntoregisterActivity"></activity> <activity android:name="turntomimaActivity"></activity> </application> </manifest>