parent
							
								
									89b1e77f63
								
							
						
					
					
						commit
						3129d3bf5a
					
				| @ -0,0 +1,40 @@ | |||||||
|  | package com.example.leudaemialikeme.Activity; | ||||||
|  | 
 | ||||||
|  | import androidx.appcompat.app.AppCompatActivity; | ||||||
|  | import androidx.recyclerview.widget.LinearLayoutManager; | ||||||
|  | import androidx.recyclerview.widget.RecyclerView; | ||||||
|  | 
 | ||||||
|  | import android.os.Bundle; | ||||||
|  | 
 | ||||||
|  | import com.example.leudaemialikeme.Adapter.AttentionAdapter; | ||||||
|  | import com.example.leudaemialikeme.Attention; | ||||||
|  | import com.example.leudaemialikeme.R; | ||||||
|  | 
 | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | public class AttentionActivity extends AppCompatActivity { | ||||||
|  | 
 | ||||||
|  |     private List<Attention> attentionList = new ArrayList<>(); | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     protected void onCreate(Bundle savedInstanceState) { | ||||||
|  |         super.onCreate(savedInstanceState); | ||||||
|  |         setContentView(R.layout.activity_attention); | ||||||
|  |         getData();//获得数据
 | ||||||
|  |         RecyclerView recycleView = (RecyclerView) findViewById(R.id.attentionList);//获得视图
 | ||||||
|  |         LinearLayoutManager layoutManager; | ||||||
|  |         layoutManager = new LinearLayoutManager(this); | ||||||
|  |         recycleView.setLayoutManager(layoutManager);//建立线性布局
 | ||||||
|  |         AttentionAdapter adapter = new AttentionAdapter(attentionList);//创建适配器
 | ||||||
|  |         recycleView.setAdapter(adapter);//将视图与适配器连接起来
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void getData() { | ||||||
|  |         Attention attention1 = new Attention(R.mipmap.img_my_person,"小白帮","管住嘴,迈开腿,多喝水"); | ||||||
|  |         attentionList.add(attention1); | ||||||
|  |         Attention attention2 = new Attention(R.mipmap.img_my_person,"小白帮","管住嘴,多饮水,常保暖"); | ||||||
|  |         attentionList.add(attention2); | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -1,17 +1,24 @@ | |||||||
| package com.example.leudaemialikeme.Activity; | package com.example.leudaemialikeme.Activity; | ||||||
| 
 | 
 | ||||||
| import androidx.appcompat.app.AppCompatActivity; | import androidx.appcompat.app.AppCompatActivity; | ||||||
|  | import androidx.fragment.app.FragmentManager; | ||||||
|  | import androidx.fragment.app.FragmentTransaction; | ||||||
| 
 | 
 | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| 
 | 
 | ||||||
|  | import com.example.leudaemialikeme.Fragment.CollectFragment; | ||||||
| import com.example.leudaemialikeme.R; | import com.example.leudaemialikeme.R; | ||||||
| 
 | 
 | ||||||
| public class CollectActivity extends AppCompatActivity { | public class CollectActivity extends AppCompatActivity  { | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     protected void onCreate(Bundle savedInstanceState) { |     protected void onCreate(Bundle savedInstanceState) { | ||||||
|         super.onCreate(savedInstanceState); |         super.onCreate(savedInstanceState); | ||||||
|         setContentView(R.layout.activity_collect); |         setContentView(R.layout.activity_collect); | ||||||
|  |         FragmentManager fm = getSupportFragmentManager(); | ||||||
|  |         FragmentTransaction trans = fm.beginTransaction(); | ||||||
|  |         String title = "我的收藏"; | ||||||
|  |         trans.replace(R.id.collect_frag_layout, new CollectFragment(title)); | ||||||
|  |         trans.commit(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -0,0 +1,24 @@ | |||||||
|  | package com.example.leudaemialikeme.Activity; | ||||||
|  | 
 | ||||||
|  | import androidx.appcompat.app.AppCompatActivity; | ||||||
|  | import androidx.fragment.app.FragmentManager; | ||||||
|  | import androidx.fragment.app.FragmentTransaction; | ||||||
|  | 
 | ||||||
|  | import android.os.Bundle; | ||||||
|  | 
 | ||||||
|  | import com.example.leudaemialikeme.Fragment.CollectFragment; | ||||||
|  | import com.example.leudaemialikeme.R; | ||||||
|  | 
 | ||||||
|  | public class HistoryActivity extends AppCompatActivity { | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     protected void onCreate(Bundle savedInstanceState) { | ||||||
|  |         super.onCreate(savedInstanceState); | ||||||
|  |         setContentView(R.layout.activity_history); | ||||||
|  |         FragmentManager fm = getSupportFragmentManager(); | ||||||
|  |         FragmentTransaction trans = fm.beginTransaction(); | ||||||
|  |         String title = "浏览历史"; | ||||||
|  |         trans.replace(R.id.collect_frag_layout, new CollectFragment(title)); | ||||||
|  |         trans.commit(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,59 @@ | |||||||
|  | package com.example.leudaemialikeme.Adapter; | ||||||
|  | 
 | ||||||
|  | import android.view.LayoutInflater; | ||||||
|  | import android.view.View; | ||||||
|  | import android.view.ViewGroup; | ||||||
|  | import android.widget.ImageView; | ||||||
|  | import android.widget.TextView; | ||||||
|  | 
 | ||||||
|  | import androidx.annotation.NonNull; | ||||||
|  | import androidx.recyclerview.widget.RecyclerView; | ||||||
|  | 
 | ||||||
|  | import com.example.leudaemialikeme.Attention; | ||||||
|  | import com.example.leudaemialikeme.Collect; | ||||||
|  | import com.example.leudaemialikeme.R; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | public class AttentionAdapter extends RecyclerView.Adapter<AttentionAdapter.ViewHolder> { | ||||||
|  |     private List<Attention> attentionList; | ||||||
|  | 
 | ||||||
|  |     //重写构造方法
 | ||||||
|  |     public AttentionAdapter(List<Attention> attentionList) { | ||||||
|  |         this.attentionList = attentionList; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public int getItemCount() { | ||||||
|  |         return attentionList.size(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     //内部类
 | ||||||
|  |     static class ViewHolder extends RecyclerView.ViewHolder { | ||||||
|  |         TextView  attentionTitle,attentionInfo; | ||||||
|  |         ImageView attentionIconId; | ||||||
|  | 
 | ||||||
|  |         public ViewHolder(@NonNull View itemView) { | ||||||
|  |             super(itemView); | ||||||
|  |             this.attentionTitle = (TextView) itemView.findViewById(R.id.attentionTitle); | ||||||
|  |             this.attentionIconId = (ImageView) itemView.findViewById(R.id.attentionIcon); | ||||||
|  |             this.attentionInfo = (TextView) itemView.findViewById(R.id.attentionInfo); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     //重写 onCreateViewHolder()方法
 | ||||||
|  |     @Override | ||||||
|  |     public AttentionAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||||||
|  |         View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.attention_item, parent, false); | ||||||
|  |         AttentionAdapter.ViewHolder holder = new AttentionAdapter.ViewHolder(view); | ||||||
|  |         return holder; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     //重写onBindViewHolder()方法
 | ||||||
|  |     @Override | ||||||
|  |     public void onBindViewHolder(@NonNull AttentionAdapter.ViewHolder holder, int position) { | ||||||
|  |         Attention attention = attentionList.get(position); | ||||||
|  |         holder.attentionTitle.setText(attention.getAttentionTitle()); | ||||||
|  |         holder.attentionInfo.setText(attention.getAttentionInfo()); | ||||||
|  |         holder.attentionIconId.setImageResource(attention.getAttentionIconId()); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,60 @@ | |||||||
|  | package com.example.leudaemialikeme.Adapter; | ||||||
|  | 
 | ||||||
|  | import android.view.LayoutInflater; | ||||||
|  | import android.view.View; | ||||||
|  | import android.view.ViewGroup; | ||||||
|  | import android.widget.ImageView; | ||||||
|  | import android.widget.TextView; | ||||||
|  | 
 | ||||||
|  | import androidx.annotation.NonNull; | ||||||
|  | import androidx.recyclerview.widget.RecyclerView; | ||||||
|  | 
 | ||||||
|  | import com.example.leudaemialikeme.Collect; | ||||||
|  | import com.example.leudaemialikeme.R; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | 
 | ||||||
|  | public class CollectAdapter extends RecyclerView.Adapter<CollectAdapter.ViewHolder>{ | ||||||
|  |     private List<Collect> collectList; | ||||||
|  | 
 | ||||||
|  |     //重写构造方法
 | ||||||
|  |     public CollectAdapter(List<Collect> collectList){ | ||||||
|  |         this.collectList = collectList; | ||||||
|  |     } | ||||||
|  |     public int getItemCount(){ | ||||||
|  |         return collectList.size(); | ||||||
|  |     } | ||||||
|  |     //内部类
 | ||||||
|  |     static class ViewHolder extends RecyclerView.ViewHolder { | ||||||
|  |         TextView collectTitle,collectName,collectContent,collectRead; | ||||||
|  |         ImageView collectIcon,collectImg; | ||||||
|  | 
 | ||||||
|  |         public ViewHolder(@NonNull View itemView){ | ||||||
|  |             super(itemView); | ||||||
|  |             this.collectTitle = (TextView)itemView.findViewById(R.id.collectTitle); | ||||||
|  |             this.collectIcon = (ImageView)itemView.findViewById(R.id.collectIcon); | ||||||
|  |             this.collectName = (TextView)itemView.findViewById(R.id.collectName); | ||||||
|  |             this.collectContent = (TextView)itemView.findViewById(R.id.collectContent); | ||||||
|  |             this.collectImg = (ImageView)itemView.findViewById(R.id.collectImg); | ||||||
|  |             this.collectRead = (TextView)itemView.findViewById(R.id.collectRead); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     //重写 onCreateViewHolder()方法
 | ||||||
|  |     @Override | ||||||
|  |     public CollectAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | ||||||
|  |         View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.collect_item,parent,false); | ||||||
|  |         CollectAdapter.ViewHolder holder=new CollectAdapter.ViewHolder(view); | ||||||
|  |         return holder; | ||||||
|  |     } | ||||||
|  |     //重写onBindViewHolder()方法
 | ||||||
|  |     @Override | ||||||
|  |     public void onBindViewHolder(@NonNull ViewHolder holder,int position){ | ||||||
|  |         Collect collect = collectList.get(position); | ||||||
|  |         holder.collectTitle.setText(collect.getCollectTitle()); | ||||||
|  |         holder.collectName.setText(collect.getCollectName()); | ||||||
|  |         holder.collectContent.setText(collect.getCollectContent()); | ||||||
|  |         holder.collectRead.setText(collect.getCollectRead()); | ||||||
|  |         holder.collectIcon.setImageResource(collect.getCollectIconId()); | ||||||
|  |         holder.collectImg.setImageResource(collect.getCollectImgId()); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,33 @@ | |||||||
|  | package com.example.leudaemialikeme.Adapter; | ||||||
|  | 
 | ||||||
|  | import androidx.fragment.app.Fragment; | ||||||
|  | import androidx.fragment.app.FragmentManager; | ||||||
|  | import androidx.fragment.app.FragmentPagerAdapter; | ||||||
|  | 
 | ||||||
|  | import com.example.leudaemialikeme.Fragment.AnswerCollectFragment; | ||||||
|  | import com.example.leudaemialikeme.Fragment.NewsCollectFragment; | ||||||
|  | 
 | ||||||
|  | public class CollectPageFragmentAdapter extends FragmentPagerAdapter { | ||||||
|  |     private String[] channelList; | ||||||
|  |     private FragmentManager fm; | ||||||
|  | 
 | ||||||
|  |     public CollectPageFragmentAdapter(FragmentManager fm, String[] channelList) { | ||||||
|  |         super(fm); | ||||||
|  |         this.channelList = channelList; | ||||||
|  |         this.fm=fm; | ||||||
|  |     } | ||||||
|  |     @Override | ||||||
|  |     public Fragment getItem(int idx) { | ||||||
|  |         String collectCategoryTitle = channelList[idx]; | ||||||
|  |         if(collectCategoryTitle.equals("        资讯      ")) | ||||||
|  |         { | ||||||
|  |             return NewsCollectFragment.newInstance(collectCategoryTitle); | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             return AnswerCollectFragment.newInstance(collectCategoryTitle); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     @Override | ||||||
|  |     public int getCount() { | ||||||
|  |         return channelList.length; | ||||||
|  |     } } | ||||||
| @ -0,0 +1,40 @@ | |||||||
|  | package com.example.leudaemialikeme; | ||||||
|  | 
 | ||||||
|  | import java.io.Serializable; | ||||||
|  | 
 | ||||||
|  | public class Attention implements Serializable { | ||||||
|  |     private static final long serialVersionUID = 1L; | ||||||
|  |     private int attentionIconId; | ||||||
|  |     private String attentionTitle; | ||||||
|  |     private String attentionInfo; | ||||||
|  | 
 | ||||||
|  |     public Attention(int attentionIconId,String attentionTitle,String attentionInfo){ | ||||||
|  |         this.attentionIconId = attentionIconId; | ||||||
|  |         this.attentionTitle = attentionTitle; | ||||||
|  |         this.attentionInfo = attentionInfo; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public int getAttentionIconId() { | ||||||
|  |         return attentionIconId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setAttentionIconId(int attentionIconId) { | ||||||
|  |         this.attentionIconId = attentionIconId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getAttentionTitle() { | ||||||
|  |         return attentionTitle; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setAttentionTitle(String attentionTitle) { | ||||||
|  |         this.attentionTitle = attentionTitle; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getAttentionInfo() { | ||||||
|  |         return attentionInfo; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setAttentionInfo(String attentionInfo) { | ||||||
|  |         this.attentionInfo = attentionInfo; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,72 @@ | |||||||
|  | package com.example.leudaemialikeme; | ||||||
|  | 
 | ||||||
|  | import java.io.Serializable; | ||||||
|  | 
 | ||||||
|  | public class Collect implements Serializable { | ||||||
|  |     private static final long serialVersionUID = 1L; | ||||||
|  | 
 | ||||||
|  |     private String collectTitle; | ||||||
|  |     private int collectIconId; | ||||||
|  |     private String collectName; | ||||||
|  |     private String collectContent; | ||||||
|  |     private int collectImgId; | ||||||
|  |     private String collectRead; | ||||||
|  | 
 | ||||||
|  |     public Collect(String collectTitle, int collectIconId, String collectName, | ||||||
|  |                    String collectContent, int collectImgId, String collectRead){ | ||||||
|  |         this.collectTitle = collectTitle; | ||||||
|  |         this.collectIconId = collectIconId; | ||||||
|  |         this.collectName = collectName; | ||||||
|  |         this.collectContent = collectContent; | ||||||
|  |         this.collectRead = collectRead; | ||||||
|  |         this.collectImgId = collectImgId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getCollectTitle() { | ||||||
|  |         return collectTitle; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setCollectTitle(String collectTitle) { | ||||||
|  |         this.collectTitle = collectTitle; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public int getCollectIconId() { | ||||||
|  |         return collectIconId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setCollectIconId(int collectIconId) { | ||||||
|  |         this.collectIconId = collectIconId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getCollectName() { | ||||||
|  |         return collectName; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setCollectName(String collectName) { | ||||||
|  |         this.collectName = collectName; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getCollectContent() { | ||||||
|  |         return collectContent; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setCollectContent(String collectContent) { | ||||||
|  |         this.collectContent = collectContent; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public int getCollectImgId() { | ||||||
|  |         return collectImgId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setCollectImgId(int collectImgId) { | ||||||
|  |         this.collectImgId = collectImgId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getCollectRead() { | ||||||
|  |         return collectRead; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setCollectRead(String collectRead) { | ||||||
|  |         this.collectRead = collectRead; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,128 @@ | |||||||
|  | package com.example.leudaemialikeme.Fragment; | ||||||
|  | 
 | ||||||
|  | import android.content.Context; | ||||||
|  | import android.net.Uri; | ||||||
|  | import android.os.Bundle; | ||||||
|  | 
 | ||||||
|  | import androidx.fragment.app.Fragment; | ||||||
|  | import androidx.fragment.app.FragmentManager; | ||||||
|  | import androidx.viewpager.widget.ViewPager; | ||||||
|  | 
 | ||||||
|  | import android.util.DisplayMetrics; | ||||||
|  | import android.view.LayoutInflater; | ||||||
|  | import android.view.View; | ||||||
|  | import android.view.ViewGroup; | ||||||
|  | import android.widget.HorizontalScrollView; | ||||||
|  | import android.widget.RadioButton; | ||||||
|  | import android.widget.RadioGroup; | ||||||
|  | import android.widget.TextView; | ||||||
|  | 
 | ||||||
|  | import com.example.leudaemialikeme.Adapter.CollectPageFragmentAdapter; | ||||||
|  | import com.example.leudaemialikeme.R; | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * A simple {@link Fragment} subclass. | ||||||
|  |  * Activities that contain this fragment must implement the | ||||||
|  |  * to handle interaction events. | ||||||
|  |  * create an instance of this fragment. | ||||||
|  |  */ | ||||||
|  | public class CollectFragment extends Fragment implements ViewPager.OnPageChangeListener{ | ||||||
|  |     private static final String ARG_CHANNEL_LIST = "channel_list"; | ||||||
|  |     private View view=null; // 碎片的布局实例
 | ||||||
|  |     private ViewPager viewPager; //内导航的碎片的容器
 | ||||||
|  |     private RadioGroup rgChannelCollect=null; // 内导航由单选按钮组构成
 | ||||||
|  |     private HorizontalScrollView hvChannelCollect=null; //单选按钮组可滚动动
 | ||||||
|  |     private String[] channelList = {"        资讯      ","      回答与文章       ", | ||||||
|  |            }; //默认的内导航栏目
 | ||||||
|  |     private CollectPageFragmentAdapter adapter; //viewPager 的适配器
 | ||||||
|  |     private TextView Name; | ||||||
|  |     private String title; | ||||||
|  | 
 | ||||||
|  |     public CollectFragment() { | ||||||
|  |         // Required empty public constructor
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public CollectFragment(String title){ | ||||||
|  |         this.title = title; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||||||
|  |                              Bundle savedInstanceState) { | ||||||
|  |         if(view==null){ | ||||||
|  |             view=inflater.inflate(R.layout.fragment_collect, container, false); | ||||||
|  |             viewPager=(ViewPager)view.findViewById(R.id.vpNewsListCollect); | ||||||
|  |             initViewPager(); //设置 ViewPager
 | ||||||
|  | 
 | ||||||
|  |             rgChannelCollect=(RadioGroup)view.findViewById(R.id.rgChannelCollect); | ||||||
|  |             hvChannelCollect=(HorizontalScrollView)view.findViewById(R.id.hvChannelCollect); | ||||||
|  |             initTab(inflater); | ||||||
|  | 
 | ||||||
|  |             Name = (TextView)view.findViewById(R.id.Name); | ||||||
|  |             Name.setText(title); | ||||||
|  |             rgChannelCollect.setOnCheckedChangeListener( | ||||||
|  |                     new RadioGroup.OnCheckedChangeListener() { | ||||||
|  |                         @Override | ||||||
|  |                         public void onCheckedChanged(RadioGroup group, int checkedId) { | ||||||
|  |                             viewPager.setCurrentItem(checkedId); | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |             ); | ||||||
|  |         } | ||||||
|  |         return view; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void initTab(LayoutInflater inflater) {//初始化上面的
 | ||||||
|  |         for(int i=0;i<channelList.length;i++){ | ||||||
|  |             RadioButton rb=(RadioButton)inflater.inflate(R.layout.invitation_tab_rb,null); | ||||||
|  |             rb.setId(i); | ||||||
|  |             rb.setText(channelList[i]); | ||||||
|  |             RadioGroup.LayoutParams params = new | ||||||
|  |                     RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, | ||||||
|  |                     RadioGroup.LayoutParams.WRAP_CONTENT); | ||||||
|  | 
 | ||||||
|  |             rgChannelCollect.addView(rb,params); | ||||||
|  |         } | ||||||
|  |         rgChannelCollect.check(0); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private void initViewPager() { //初始化ViewPager
 | ||||||
|  |         FragmentManager fragmentManager = super.getActivity().getSupportFragmentManager(); | ||||||
|  |         // adapter=new MessagePageFragmentAdapter(fragmentManager, channelList);
 | ||||||
|  |         adapter=new CollectPageFragmentAdapter(fragmentManager, channelList); | ||||||
|  | //参数 channelList 将被适配器用来在动态切换碎片的时候实时创建碎片 //设置 ViewPager 的适配器
 | ||||||
|  |         viewPager.setAdapter(adapter); | ||||||
|  |         viewPager.setOffscreenPageLimit(2); | ||||||
|  |         //设置显示第 1 个碎片
 | ||||||
|  |         viewPager.setCurrentItem(0);//这里设置显示第一个碎片
 | ||||||
|  |         //设置 ViewPager 的切换监听
 | ||||||
|  |         viewPager.addOnPageChangeListener(this); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void onPageSelected(int position) { | ||||||
|  |         setTab(position); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void onPageScrollStateChanged(int state) { | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  |     private void setTab(int idx){ | ||||||
|  |         RadioButton rb=(RadioButton)rgChannelCollect.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;
 | ||||||
|  |         int len=left+width/2-screenWidth/2; | ||||||
|  |         hvChannelCollect.smoothScrollTo(len,0); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,54 @@ | |||||||
|  | <?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" | ||||||
|  |     android:orientation="vertical" | ||||||
|  |     tools:context="com.example.leudaemialikeme.Activity.AttentionActivity"> | ||||||
|  | 
 | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_marginTop="10dp" | ||||||
|  |         android:orientation="horizontal"> | ||||||
|  | 
 | ||||||
|  |         <ImageView | ||||||
|  |             android:layout_width="30dp" | ||||||
|  |             android:layout_height="30dp" | ||||||
|  |             android:layout_margin="15dp" | ||||||
|  |             android:src="@mipmap/img_go_answer_return" | ||||||
|  |             /> | ||||||
|  | 
 | ||||||
|  |         <TextView | ||||||
|  |             android:id="@+id/text_attention" | ||||||
|  |             android:layout_width="wrap_content" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_weight="3" | ||||||
|  |             android:textSize="18dp" | ||||||
|  |             android:gravity="center" | ||||||
|  |             android:layout_gravity="center" | ||||||
|  |             android:text="关注" /> | ||||||
|  | 
 | ||||||
|  |         <TextView | ||||||
|  |             android:id="@+id/find" | ||||||
|  |             android:layout_width="wrap_content" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:textSize="18dp" | ||||||
|  |             android:gravity="center" | ||||||
|  |             android:layout_gravity="center" | ||||||
|  |             android:text="发现用户" /> | ||||||
|  |     </LinearLayout> | ||||||
|  |     <View | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="2dp" | ||||||
|  |         android:background="@color/light_grey" | ||||||
|  |         /> | ||||||
|  | 
 | ||||||
|  |     <androidx.recyclerview.widget.RecyclerView | ||||||
|  |         android:id="@+id/attentionList" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="match_parent" /> | ||||||
|  | </LinearLayout> | ||||||
| @ -1,9 +1,15 @@ | |||||||
| <?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||||||
| <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" |     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||||
|     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="com.example.leudaemialikeme.Activity.CollectActivity"> |     tools:context="com.example.leudaemialikeme.Activity.CollectActivity"> | ||||||
| 
 | 
 | ||||||
| </androidx.constraintlayout.widget.ConstraintLayout> |     <FrameLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="match_parent" | ||||||
|  |         android:id="@+id/collect_frag_layout"> | ||||||
|  |     </FrameLayout> | ||||||
|  | </LinearLayout> | ||||||
|  | |||||||
| @ -0,0 +1,15 @@ | |||||||
|  | <?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" | ||||||
|  |     android:orientation="vertical" | ||||||
|  |     tools:context="com.example.leudaemialikeme.Activity.HistoryActivity"> | ||||||
|  | 
 | ||||||
|  |     <FrameLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="match_parent" | ||||||
|  |         android:id="@+id/collect_frag_layout"> | ||||||
|  |     </FrameLayout> | ||||||
|  | </LinearLayout> | ||||||
| @ -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="wrap_content"> | ||||||
|  | 
 | ||||||
|  |     <ImageView | ||||||
|  |         android:layout_width="40dp" | ||||||
|  |         android:layout_height="40dp" | ||||||
|  |         android:layout_margin="10dp" | ||||||
|  |         android:layout_weight="1" | ||||||
|  |         android:id="@+id/attentionIcon" | ||||||
|  |         /> | ||||||
|  | 
 | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="50dp" | ||||||
|  |         android:layout_margin="10dp" | ||||||
|  |         android:layout_weight="4" | ||||||
|  |         android:orientation="vertical"> | ||||||
|  | 
 | ||||||
|  |         <TextView | ||||||
|  |             android:id="@+id/attentionTitle" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_marginBottom="10dp" | ||||||
|  |             android:textSize="16dp" /> | ||||||
|  | 
 | ||||||
|  |         <TextView | ||||||
|  |             android:id="@+id/attentionInfo" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |              /> | ||||||
|  | 
 | ||||||
|  |     </LinearLayout> | ||||||
|  | 
 | ||||||
|  |     <Button | ||||||
|  |         android:id="@+id/button" | ||||||
|  |         android:layout_width="30dp" | ||||||
|  |         android:layout_height="30dp" | ||||||
|  |         android:layout_weight="1" | ||||||
|  |         android:layout_margin="20dp" | ||||||
|  |         android:background="@drawable/shape_round_corner" | ||||||
|  |         android:text="已关注" /> | ||||||
|  | 
 | ||||||
|  | </LinearLayout> | ||||||
| @ -0,0 +1,80 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <LinearLayout | ||||||
|  |     xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     android:orientation="vertical" | ||||||
|  |     android:background="@drawable/shape_round_corner" | ||||||
|  |     android:layout_width="match_parent" | ||||||
|  |     android:layout_margin="10dp" | ||||||
|  |     android:layout_height="wrap_content"> | ||||||
|  | 
 | ||||||
|  |     <TextView | ||||||
|  |         android:id="@+id/collectTitle" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:textSize="18dp" | ||||||
|  |         android:layout_marginTop="10dp" | ||||||
|  |         android:layout_marginLeft="10dp" | ||||||
|  |         /> | ||||||
|  | 
 | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_margin="8dp" | ||||||
|  |         android:orientation="horizontal"> | ||||||
|  | 
 | ||||||
|  |         <LinearLayout | ||||||
|  |             android:layout_width="wrap_content" | ||||||
|  |             android:layout_height="60dp" | ||||||
|  |             android:layout_weight="3" | ||||||
|  |             android:orientation="vertical"> | ||||||
|  | 
 | ||||||
|  |             <LinearLayout | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:layout_weight="2" | ||||||
|  |                 android:orientation="horizontal"> | ||||||
|  | 
 | ||||||
|  |                 <ImageView | ||||||
|  |                     android:layout_width="30dp" | ||||||
|  |                     android:layout_height="30dp" | ||||||
|  |                     android:layout_marginLeft="10dp" | ||||||
|  |                     android:id="@+id/collectIcon" | ||||||
|  |                     /> | ||||||
|  | 
 | ||||||
|  |                 <TextView | ||||||
|  |                     android:id="@+id/collectName" | ||||||
|  |                     android:layout_width="wrap_content" | ||||||
|  |                     android:layout_height="wrap_content" | ||||||
|  |                     android:layout_weight="1" | ||||||
|  |                     android:textSize="14dp" | ||||||
|  |                     android:layout_marginLeft="20dp" | ||||||
|  |                     android:layout_gravity="center" | ||||||
|  |                     /> | ||||||
|  |             </LinearLayout> | ||||||
|  |             <TextView | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:textSize="16dp" | ||||||
|  |                 android:id="@+id/collectContent" | ||||||
|  |                 android:layout_marginLeft="10dp" | ||||||
|  |                 android:layout_weight="1" | ||||||
|  | 
 | ||||||
|  |                 /> | ||||||
|  |         </LinearLayout> | ||||||
|  |         <ImageView | ||||||
|  |             android:layout_width="40dp" | ||||||
|  |             android:layout_height="40dp" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:id="@+id/collectImg" | ||||||
|  |             /> | ||||||
|  |     </LinearLayout> | ||||||
|  | 
 | ||||||
|  |     <TextView | ||||||
|  |         android:id="@+id/collectRead" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:textSize="16dp" | ||||||
|  |         android:layout_marginLeft="20dp" | ||||||
|  |         android:layout_marginBottom="10dp" | ||||||
|  |         /> | ||||||
|  | </LinearLayout> | ||||||
| @ -0,0 +1,23 @@ | |||||||
|  | <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="com.example.leudaemialikeme.Fragment.AnswerCollectFragment"> | ||||||
|  | 
 | ||||||
|  |     <androidx.swiperefreshlayout.widget.SwipeRefreshLayout | ||||||
|  |         android:id="@+id/refresh_layout" | ||||||
|  |         android:layout_height="match_parent" | ||||||
|  |         android:layout_width="match_parent"> | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="match_parent" | ||||||
|  |         android:orientation="vertical"> | ||||||
|  | 
 | ||||||
|  |         <androidx.recyclerview.widget.RecyclerView | ||||||
|  |             android:id="@+id/APNList" | ||||||
|  |             android:background="@color/light_grey" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="match_parent" /> | ||||||
|  |     </LinearLayout> | ||||||
|  |     </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> | ||||||
|  | </FrameLayout> | ||||||
| @ -0,0 +1,72 @@ | |||||||
|  | <LinearLayout 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" | ||||||
|  |     android:orientation="vertical" | ||||||
|  |     tools:context="com.example.leudaemialikeme.Fragment.CollectFragment"> | ||||||
|  | 
 | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="50dp" | ||||||
|  |         android:orientation="horizontal"> | ||||||
|  | 
 | ||||||
|  |         <LinearLayout | ||||||
|  |             android:layout_width="265dp" | ||||||
|  |             android:layout_height="match_parent" | ||||||
|  |             android:layout_weight="20"> | ||||||
|  |             <ImageView | ||||||
|  |                 android:id="@+id/imageButton2" | ||||||
|  |                 android:layout_width="30dp" | ||||||
|  |                 android:layout_height="30dp" | ||||||
|  |                 android:layout_margin="10dp" | ||||||
|  |                 android:src="@mipmap/img_go_answer_return" /> | ||||||
|  | 
 | ||||||
|  |             <TextView | ||||||
|  |                 android:id="@+id/Name" | ||||||
|  |                 android:layout_width="wrap_content" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:layout_margin="10dp" | ||||||
|  |                 android:layout_weight="20" | ||||||
|  |                 android:gravity="center" | ||||||
|  |                 android:textSize="20dp" /> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         </LinearLayout> | ||||||
|  |     </LinearLayout> | ||||||
|  | 
 | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content" | ||||||
|  |         android:layout_margin="10dp" | ||||||
|  |         android:orientation="vertical"> | ||||||
|  | 
 | ||||||
|  |         <RelativeLayout | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="wrap_content" | ||||||
|  |             android:layout_marginTop="10dp"> | ||||||
|  |             <!-- 导航标签,包含一个单选按钮组--> | ||||||
|  |             <!-- 任意数量不能显示时的缩略符号 --> | ||||||
|  |             <HorizontalScrollView | ||||||
|  |                 android:id="@+id/hvChannelCollect" | ||||||
|  |                 android:layout_width="match_parent" | ||||||
|  |                 android:layout_height="wrap_content" | ||||||
|  |                 android:layout_toLeftOf="@+id/ivShowChannel" | ||||||
|  |                 android:scrollbars="none"> | ||||||
|  | 
 | ||||||
|  |                 <RadioGroup | ||||||
|  |                     android:id="@+id/rgChannelCollect" | ||||||
|  |                     android:layout_width="wrap_content" | ||||||
|  |                     android:layout_height="wrap_content" | ||||||
|  |                     android:orientation="horizontal" /> | ||||||
|  |             </HorizontalScrollView> | ||||||
|  |         </RelativeLayout> | ||||||
|  |     </LinearLayout> | ||||||
|  | 
 | ||||||
|  |     <androidx.viewpager.widget.ViewPager | ||||||
|  |         android:id="@+id/vpNewsListCollect" | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="0dp" | ||||||
|  |         android:layout_weight="1" | ||||||
|  |         /> | ||||||
|  | 
 | ||||||
|  | </LinearLayout> | ||||||
| @ -0,0 +1,24 @@ | |||||||
|  | <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="com.example.leudaemialikeme.Fragment.NewsCollectFragment"> | ||||||
|  | 
 | ||||||
|  |     <androidx.swiperefreshlayout.widget.SwipeRefreshLayout | ||||||
|  |         android:id="@+id/refresh_layout" | ||||||
|  |         android:layout_height="match_parent" | ||||||
|  |         android:layout_width="match_parent"> | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="match_parent" | ||||||
|  |         android:orientation="vertical"> | ||||||
|  | 
 | ||||||
|  |         <androidx.recyclerview.widget.RecyclerView | ||||||
|  |             android:id="@+id/APNList" | ||||||
|  |             android:background="@color/light_grey" | ||||||
|  |             android:layout_width="match_parent" | ||||||
|  |             android:layout_height="match_parent" /> | ||||||
|  |     </LinearLayout> | ||||||
|  |     </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> | ||||||
|  | </FrameLayout> | ||||||
					Loading…
					
					
				
		Reference in new issue