parent
d52d98cbe4
commit
d3bb92290b
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="PROJECT" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/dpdb.iml" filepath="$PROJECT_DIR$/.idea/dpdb.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -1,14 +1,102 @@
|
|||||||
package com.example.dxsdpdb;
|
package com.example.dxsdpdb;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private List<Fragment> mFragments;
|
||||||
|
|
||||||
|
private LinearLayout mIndexPage;
|
||||||
|
private LinearLayout mMissionPage;
|
||||||
|
private LinearLayout mMinePage;
|
||||||
|
|
||||||
|
// private ImageButton mImgIndexPage;
|
||||||
|
// private ImageButton mImgMissionPage;
|
||||||
|
// private ImageButton mImgMinePage;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
//去除标题栏
|
||||||
|
getSupportActionBar().hide();
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
initFragments(); //初始化数据
|
||||||
|
initViews(); //初始化控件
|
||||||
|
initEvents(); //初始化事件
|
||||||
|
initFirstRun(0);//第一次运行初始化界面,第一个碎片
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initFragments() {
|
||||||
|
mFragments = new ArrayList<>();
|
||||||
|
//将四个 Fragment 加入集合中
|
||||||
|
mFragments.add(new IndexFragment());
|
||||||
|
mFragments.add(new MissionFragment());
|
||||||
|
mFragments.add(new MineFragment());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initViews() {
|
||||||
|
mIndexPage = (LinearLayout) findViewById(R.id.id_index);
|
||||||
|
mMissionPage = (LinearLayout) findViewById(R.id.id_tab_mission);
|
||||||
|
mMinePage = (LinearLayout) findViewById(R.id.id_tab_mine);
|
||||||
|
// mImgIndexPage = (ImageButton) findViewById(R.id.id_tab_index_img);
|
||||||
|
// mImgMissionPage = (ImageButton) findViewById(R.id.id_tab_mission_img);
|
||||||
|
// mImgMinePage = (ImageButton) findViewById(R.id.id_tab_mine_img);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initEvents() {
|
||||||
|
View.OnClickListener onClickListener = new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
//先将三个 ImageButton 置为蓝色
|
||||||
|
resetBackgroud();
|
||||||
|
//根据点击的 Tab 切换不同的页面及设置对应的 ImageButton 为白色
|
||||||
|
switch (v.getId()) {
|
||||||
|
case R.id.id_index: selectTab(0); break;
|
||||||
|
case R.id.id_tab_mission: selectTab(1); break;
|
||||||
|
case R.id.id_tab_mine: selectTab(2); break;
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
//设置三个 Tab 的点击事件
|
||||||
|
mIndexPage.setOnClickListener(onClickListener);
|
||||||
|
mMissionPage.setOnClickListener(onClickListener);
|
||||||
|
mMinePage.setOnClickListener(onClickListener);
|
||||||
|
}
|
||||||
|
private void resetBackgroud() {
|
||||||
|
mIndexPage.setBackgroundColor(getResources().getColor(R.color.blue));
|
||||||
|
mMissionPage.setBackgroundColor(getResources().getColor(R.color.blue));
|
||||||
|
mMinePage.setBackgroundColor(getResources().getColor(R.color.blue));
|
||||||
|
}
|
||||||
|
private void selectTab(int i) {
|
||||||
|
//根据点击的 Tab 设置对应的 tab 为白色
|
||||||
|
switch (i) {
|
||||||
|
case 0: mIndexPage.setBackgroundColor(getResources().getColor(R.color.blue0));break;
|
||||||
|
case 1: mMissionPage.setBackgroundColor(getResources().getColor(R.color.blue0));break;
|
||||||
|
case 2: mMinePage.setBackgroundColor(getResources().getColor(R.color.blue0));break;
|
||||||
|
}
|
||||||
|
//设置当前点击的 Tab 所对应的页面
|
||||||
|
setCurrentFragment(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCurrentFragment(int i)
|
||||||
|
{
|
||||||
|
FragmentManager fm = getSupportFragmentManager();
|
||||||
|
FragmentTransaction trans = fm.beginTransaction();
|
||||||
|
trans.replace(R.id.frag_layout, mFragments.get(i));
|
||||||
|
trans.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initFirstRun(int i)
|
||||||
|
{
|
||||||
|
resetBackgroud(); //重置所有 Tab
|
||||||
|
selectTab(i); //显示第 i 个碎片
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,63 +1,111 @@
|
|||||||
package com.example.dxsdpdb;
|
package com.example.dxsdpdb;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.HorizontalScrollView;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
/**
|
public class MissionFragment extends Fragment implements ViewPager.OnPageChangeListener {
|
||||||
* A simple {@link Fragment} subclass.
|
|
||||||
* Use the {@link MissionFragment#newInstance} factory method to
|
|
||||||
* create an instance of this fragment.
|
|
||||||
*/
|
|
||||||
public class MissionFragment extends Fragment {
|
|
||||||
|
|
||||||
// TODO: Rename parameter arguments, choose names that match
|
private View view=null; // 碎片的布局实例
|
||||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
private ViewPager viewPager; //内导航的碎片的容器
|
||||||
private static final String ARG_PARAM1 = "param1";
|
private RadioGroup rgChannel=null; // 内导航由单选按钮组构成
|
||||||
private static final String ARG_PARAM2 = "param2";
|
private HorizontalScrollView hvChannel=null; //单选按钮组可滚动动
|
||||||
|
private String[] channelList = {"全部任务","待付款","待接受","待完成","已完成","已过期"}; //默认的内导航栏目
|
||||||
|
private MissionFragmentAdapter adapter; //viewPager 的适配器
|
||||||
|
|
||||||
// TODO: Rename and change types of parameters
|
@Override
|
||||||
private String mParam1;
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
private String mParam2;
|
super.onCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
public MissionFragment() {
|
public MissionFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Use this factory method to create a new instance of
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
* this fragment using the provided parameters.
|
Bundle savedInstanceState) {
|
||||||
*
|
// Inflate the layout for this fragment
|
||||||
* @param param1 Parameter 1.
|
if(view==null){
|
||||||
* @param param2 Parameter 2.
|
view=inflater.inflate(R.layout.fragment_mission, container, false);
|
||||||
* @return A new instance of fragment MissionFragment.
|
viewPager=(ViewPager)view.findViewById(R.id.vpNewsList);
|
||||||
*/
|
initViewPager(); //设置 ViewPager
|
||||||
// TODO: Rename and change types and number of parameters
|
rgChannel=(RadioGroup)view.findViewById(R.id.rgChannel);
|
||||||
public static MissionFragment newInstance(String param1, String param2) {
|
hvChannel=(HorizontalScrollView)view.findViewById(R.id.hvChannel);
|
||||||
MissionFragment fragment = new MissionFragment();
|
initTab(inflater); //初始化内导航标签
|
||||||
Bundle args = new Bundle();
|
rgChannel.setOnCheckedChangeListener( //单选按钮的监听事件响应
|
||||||
args.putString(ARG_PARAM1, param1);
|
new RadioGroup.OnCheckedChangeListener() {
|
||||||
args.putString(ARG_PARAM2, param2);
|
@Override
|
||||||
fragment.setArguments(args);
|
public void onCheckedChanged(RadioGroup group,int checkedId) {
|
||||||
return fragment;
|
//单击某个选项按钮时 viewPager 进行切换
|
||||||
|
viewPager.setCurrentItem(checkedId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void initTab(LayoutInflater inflater){
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
for(int i=0;i<channelList.length;i++){//以下添加单选按钮的实例到内导航
|
||||||
super.onCreate(savedInstanceState);
|
RadioButton rb=(RadioButton)inflater.inflate(R.layout.tab_rb, null);
|
||||||
if (getArguments() != null) {
|
rb.setId(i);
|
||||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
rb.setText(channelList[i]);
|
||||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
RadioGroup.LayoutParams params=new
|
||||||
|
RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT,
|
||||||
|
RadioGroup.LayoutParams.WRAP_CONTENT);
|
||||||
|
rgChannel.addView(rb,params);
|
||||||
}
|
}
|
||||||
|
rgChannel.check(0); //第一个选项
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//设置 ViewPager 容器的适配器。
|
||||||
|
|
||||||
|
private void initViewPager(){
|
||||||
|
FragmentManager fragmentManager = super.getActivity().getSupportFragmentManager();
|
||||||
|
//参数 channelList 将被适配器用来在动态切换碎片的时候实时创建碎片
|
||||||
|
adapter=new MissionFragmentAdapter(fragmentManager, channelList);
|
||||||
|
//设置 ViewPager 的适配器
|
||||||
|
viewPager.setAdapter(adapter);
|
||||||
|
viewPager.setOffscreenPageLimit(2);
|
||||||
|
//设置显示第 1 个碎片
|
||||||
|
viewPager.setCurrentItem(0);
|
||||||
|
//设置 ViewPager 的切换监听
|
||||||
|
viewPager.addOnPageChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//以下三个方法是 ViewPager 的切换监听器 ViewPager.OnPageChangeListener 的事件处理方法
|
||||||
|
//ViewPager.OnPageChangeListener 的实现采用了接口的方式
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public void onPageScrolled(int i, float v, int i1) {
|
||||||
Bundle savedInstanceState) {
|
|
||||||
// Inflate the layout for this fragment
|
|
||||||
return inflater.inflate(R.layout.fragment_mission, container, false);
|
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
//某个碎片被选中时的动作,对应的内导航标签将要滑动到屏幕中央,并且有下划线显示
|
||||||
|
public void onPageSelected(int i) {
|
||||||
|
setTab(i);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onPageScrollStateChanged(int i) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTab(int idx){
|
||||||
|
RadioButton rb=(RadioButton)rgChannel.getChildAt(idx);
|
||||||
|
rb.setChecked(true);
|
||||||
|
int left=rb.getLeft();
|
||||||
|
int width=rb.getMeasuredWidth();
|
||||||
|
DisplayMetrics metrics=new DisplayMetrics();
|
||||||
|
super.getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||||
|
int screenWidth=metrics.widthPixels;
|
||||||
|
int len=left+width/2-screenWidth/2;
|
||||||
|
hvChannel.smoothScrollTo(len, 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,14 +1,111 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:src="@drawable/me">
|
||||||
|
</ImageView>
|
||||||
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MineFragment">
|
android:textSize="50sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:text="用户空间">
|
||||||
|
|
||||||
<!-- TODO: Update blank fragment layout -->
|
</TextView>
|
||||||
<TextView
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/money">
|
||||||
|
|
||||||
|
</ImageView>
|
||||||
|
<Button
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="30sp"
|
||||||
|
android:text="余额">
|
||||||
|
</Button>
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/quan">
|
||||||
|
|
||||||
|
</ImageView>
|
||||||
|
<Button
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textSize="30sp"
|
||||||
|
android:text="优惠券"></Button>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="150dp"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:src="@drawable/vip">
|
||||||
|
</ImageView>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:text="跑腿达人立即认证"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:textStyle="italic"></Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:text="订阅消息"></Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:text="@string/hello_blank_fragment" />
|
android:textSize="25sp"
|
||||||
|
android:text="我的地址"></Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:text="我的体现"></Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:text="在线客服"></Button>
|
||||||
|
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:text="帮助中心"></Button>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</LinearLayout>
|
@ -1,14 +1,32 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
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=".MissionFragment">
|
tools:context=".MissionFragment">
|
||||||
|
|
||||||
<!-- TODO: Update blank fragment layout -->
|
<!-- TODO: Update blank fragment layout -->
|
||||||
<TextView
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content">
|
||||||
android:text="@string/hello_blank_fragment" />
|
<!-- 导航标签,包含一个单选按钮组-->
|
||||||
|
<HorizontalScrollView
|
||||||
</FrameLayout>
|
android:id="@+id/hvChannel"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="none">
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/rgChannel"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
</RadioGroup>
|
||||||
|
</HorizontalScrollView>
|
||||||
|
</RelativeLayout>
|
||||||
|
<androidx.viewpager.widget.ViewPager
|
||||||
|
android:id="@+id/vpNewsList"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"/>
|
||||||
|
</LinearLayout>
|
Loading…
Reference in new issue