@ -0,0 +1,45 @@
|
||||
package com.example.ChatContentPkg;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.example.cmknowledgegraph.R;
|
||||
import com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecyclerViewFragment extends Fragment {
|
||||
public static Fragment newInstance(){return new RecyclerViewFragment();}
|
||||
final List<Object> items = new ArrayList<>();
|
||||
static final int ITEMS = 3;
|
||||
|
||||
RecyclerView mRecyclerView;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_recyclerview, container, false);
|
||||
}
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mRecyclerView=view.findViewById(R.id.recyclerView);
|
||||
for (int i=0;i<ITEMS;i++){
|
||||
items.add(new Object());
|
||||
|
||||
}
|
||||
|
||||
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.addItemDecoration(new MaterialViewPagerHeaderDecorator());
|
||||
mRecyclerView.setAdapter(new RecyclerViewPagerAdapter(items));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.example.ChatContentPkg;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.example.cmknowledgegraph.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RecyclerViewPagerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
List<Object> contents;
|
||||
public RecyclerViewPagerAdapter(List<Object> contents) {
|
||||
this.contents = contents;
|
||||
}
|
||||
public int getItemCount() {
|
||||
return contents.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = null;
|
||||
view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.content_cardview, parent, false);
|
||||
|
||||
return new RecyclerView.ViewHolder(view) {
|
||||
};
|
||||
|
||||
}
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,138 @@
|
||||
package com.example.cmknowledgegraph;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.example.ChatContentPkg.RecyclerViewFragment;
|
||||
import com.github.florent37.materialviewpager.MaterialViewPager;
|
||||
import com.github.florent37.materialviewpager.header.HeaderDesign;
|
||||
|
||||
public class ChatContent extends Fragment{
|
||||
AppCompatActivity appCompatActivity;//获取到Activity
|
||||
|
||||
public AppCompatActivity getAppCompatActivity() {
|
||||
return appCompatActivity;
|
||||
}
|
||||
|
||||
public void setAppCompatActivity(AppCompatActivity appCompatActivity) {
|
||||
this.appCompatActivity = appCompatActivity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
//要加载的layout文件
|
||||
return inflater.inflate(R.layout.activity_chat, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
//包装处理逻辑
|
||||
//得到MaterViewPager实例
|
||||
MaterialViewPager materialViewPager = (MaterialViewPager) getActivity().findViewById(R.id.materialViewPager);
|
||||
//为MaterialViewPager添加监听
|
||||
materialViewPager.setMaterialViewPagerListener(new MaterialViewPager.Listener() {
|
||||
@Override
|
||||
//设置转换动画和图片,颜色
|
||||
public HeaderDesign getHeaderDesign(int page) {
|
||||
switch (page){
|
||||
case 0:
|
||||
return HeaderDesign.fromColorResAndDrawable(
|
||||
R.color.blue,
|
||||
getResources().getDrawable(R.drawable.draw5)
|
||||
);
|
||||
case 1:
|
||||
return HeaderDesign.fromColorResAndDrawable(
|
||||
R.color.green,
|
||||
getResources().getDrawable(R.drawable.draw6)
|
||||
);
|
||||
case 2:
|
||||
return HeaderDesign.fromColorResAndDrawable(
|
||||
R.color.cyan,
|
||||
getResources().getDrawable(R.drawable.draw7)
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
//设置Toolbar
|
||||
Toolbar toolbar = materialViewPager.getToolbar();
|
||||
AppCompatActivity ap = getAppCompatActivity();
|
||||
if(toolbar!=null){
|
||||
ap.setSupportActionBar(toolbar);
|
||||
ActionBar actionBar = ap.getSupportActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setDisplayUseLogoEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
}
|
||||
//为Viewpager设置适配器
|
||||
ViewPager viewPager = materialViewPager.getViewPager();
|
||||
|
||||
viewPager.setAdapter(new FragmentStatePagerAdapter(getChildFragmentManager()) {
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
switch (position % 3){
|
||||
case 0:
|
||||
return RecyclerViewFragment.newInstance();
|
||||
default:
|
||||
return RecyclerViewFragment.newInstance();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position % 3){
|
||||
case 0:
|
||||
return "论坛";
|
||||
case 1:
|
||||
return "drug";
|
||||
case 2:
|
||||
return "药友";
|
||||
default:
|
||||
return "TAPN";
|
||||
}
|
||||
}
|
||||
});
|
||||
materialViewPager.getViewPager().setOffscreenPageLimit(materialViewPager
|
||||
.getViewPager().getAdapter().getCount());
|
||||
materialViewPager.getPagerTitleStrip().setViewPager(materialViewPager.getViewPager());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 543 B |
After Width: | Height: | Size: 687 B |
After Width: | Height: | Size: 1013 B |
After Width: | Height: | Size: 1.8 MiB |
After Width: | Height: | Size: 297 KiB |
After Width: | Height: | Size: 279 KiB |
After Width: | Height: | Size: 2.6 MiB |
@ -0,0 +1,30 @@
|
||||
<?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:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context=".MainActivity"
|
||||
tools:showIn="@layout/activity_main">
|
||||
<com.github.florent37.materialviewpager.MaterialViewPager
|
||||
android:id="@+id/materialViewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:viewpager_logo="@layout/header_logo"
|
||||
app:viewpager_logoMarginTop="100dp"
|
||||
app:viewpager_color="@color/colorPrimary"
|
||||
app:viewpager_headerHeight="200dp"
|
||||
app:viewpager_headerAlpha="1.0"
|
||||
app:viewpager_hideLogoWithFade="false"
|
||||
app:viewpager_hideToolbarAndTitle="true"
|
||||
app:viewpager_enableToolbarElevation="true"
|
||||
app:viewpager_parallaxHeaderFactor="1.5"
|
||||
app:viewpager_headerAdditionalHeight="20dp"
|
||||
app:viewpager_displayToolbarWhenSwipe="true"
|
||||
app:viewpager_transparentToolbar="true"
|
||||
app:viewpager_animatedHeaderImage="true"
|
||||
app:viewpager_disableToolbar="false"
|
||||
|
||||
/>
|
||||
</LinearLayout>
|
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/card_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"
|
||||
android:layout_marginBottom="@dimen/cardMarginVertical"
|
||||
android:layout_marginLeft="@dimen/cardMarginHorizontal"
|
||||
android:layout_marginRight="@dimen/cardMarginHorizontal"
|
||||
android:layout_marginTop="@dimen/cardMarginVertical"
|
||||
app:cardCornerRadius="2dp"
|
||||
app:cardElevation="2dp"
|
||||
app:cardPreventCornerOverlap="false"
|
||||
android:clickable="true"
|
||||
app:contentPadding="0dp">
|
||||
android:foreground="?android:attr/selectableItemBackgroundBorderless"
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
|
||||
</FrameLayout>
|
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
||||
/>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/logo_white"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/materialviewpager_logoHeight"
|
||||
android:text="Health is Everything"
|
||||
android:textSize="30sp"
|
||||
android:textColor="@android:color/white"/>
|
||||
|
||||
|
||||
|
@ -1,11 +1,43 @@
|
||||
<resources>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
|
||||
</style>
|
||||
<style name="AppTheme" parent="AppBaseTheme">
|
||||
<!-- Customize your theme here. -->
|
||||
<!-- <item name="colorPrimary">@color/colorPrimary</item>-->
|
||||
<!-- <item name="colorPrimaryDark">@color/colorPrimaryDark</item>-->
|
||||
<!-- <item name="colorAccent">@color/colorAccent</item>-->
|
||||
|
||||
|
||||
<item name="android:textColorPrimary">@android:color/white</item>
|
||||
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
|
||||
<item name="android:windowTranslucentStatus" tools:targetApi="21">true</item>
|
||||
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
|
||||
<!-- Toolbar Theme / Apply white arrow -->
|
||||
<item name="colorControlNormal">@android:color/white</item>
|
||||
<item name="actionBarTheme">@style/AppTheme.ActionBarTheme</item>
|
||||
|
||||
<!-- Material Theme -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="colorAccent">@color/accent_color</item>
|
||||
|
||||
<item name="android:navigationBarColor" tools:targetApi="21">@color/navigationBarColor</item>
|
||||
<item name="android:windowDrawsSystemBarBackgrounds" tools:targetApi="21">true</item>
|
||||
|
||||
</style>
|
||||
<style name="AppTheme.ActionBarTheme" parent="@style/ThemeOverlay.AppCompat.ActionBar">
|
||||
<!-- White arrow -->
|
||||
<item name="colorControlNormal">@android:color/white</item>
|
||||
</style>
|
||||
|
||||
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
|
||||
<item name="spinBars">true</item>
|
||||
<item name="color">@color/drawerArrowColor</item>
|
||||
</style>
|
||||
</resources>
|
||||
|