点击+号进入编辑(1)

 首先在frgment01布局里面修改一下布局 改成线性布局 然后吧横滑扔进去,随后设置一个图片用 drawable创建一个图片并且修改颜色如图下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
    这是跟一个标题栏一样的宽度后面带着+号 
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:layout_height="50dp">
     横滑控件嵌套这里
    <android.support.design.widget.TabLayout
        android:id="@+id/design_view"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        加这个可以均匀分布而且滑动
        app:tabMode="scrollable"
        >
    </android.support.design.widget.TabLayout>
     这是+号图标
    <ImageView
        android:id="@+id/add_1"
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:src="@drawable/ic_add_black_24dp"
        />
</LinearLayout>
    <android.support.v4.view.ViewPager

    android:id="@+id/view_par22"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    > 布局完成之后回到 Fragment01页面初始化控件
定义控件属性1
private TabLayout design_view;
private ImageView add_1;
//2**初始化控件
design_view=view.findViewById(R.id.design_view);
add_1= view.findViewById(R.id.add_1);
add_1.setOnClickListener(this);

3在填充页面中写上这个相连接 如下

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    fragments=new ArrayList<>();
    fragments.add(new YiFragment());
    fragments.add(new ErFragment());
    fragments.add(new SanFragment());
    fragments.add(new SiFragment());
    view_par22.setAdapter(new ParvAdapter(getChildFragmentManager(),fragments));
  ////////***就是这一行
    design_view.setupWithViewPager(view_par22); //3去布局页面那个图片加个id

}

4之后写个方法跳转 意思是点击图片之后进入另外一个页面

@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.add_1:
            startActivity(new Intent(getActivity(),AddActivity.class));
            break;
    }
}

////5在MainActivity页面包含的那个分文件夹里右键-Activity-EmptyActivity创建个页面只改前面的名字其余的不要动(包括下面的那个对号)创建成功后在这个创建的页面布局中写

<?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=".url.AddActivity">
  表示标题宽度跟背景颜色
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/colorPrimaryDark"
    >
  这个图片代表前面那个返回的东西 (就是这个《-)
    <ImageView
        android:id="@+id/fanhui_layout"
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:padding="10dp"
        android:src="@drawable/ic_arrow_pingdao_24dp"
        />
   这个是中间标题没什么用
    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:text="频道管理"
        android:gravity="center"
        android:textColor="#FFFAF0"
        android:textSize="20sp"
        />
  这个是点下编辑会出现编辑的东西
 <TextView
     android:id="@+id/bianji_layout"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="编辑"
     android:textSize="20sp"
     android:gravity="center"
     />
     
</LinearLayout>
 这个需要那个网址导入依赖跟添加一个url的东西
    <com.bawei.channelmanager.ui.ChannelView
        android:id="@+id/cha_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </com.bawei.channelmanager.ui.ChannelView>
</LinearLayout>

随后就开始写频道管理器主页面了,首先还是定义控件

代表编辑的控件 private TextView bianji_layout;

代表那个返回的小箭头控件 private ImageView fanhui_layout;

这个最重要代表频道管理器控件 private ChannelView cha_view;

初始化这三个

bianji_layout=  findViewById(R.id.bianji_layout);
 fanhui_layout = findViewById(R.id.fanhui_layout);
cha_view=findViewById(R.id.cha_view);

第三步按照那个网站的代码写如下一定要一样

private List<ChannelBean> lovechannelBeans =new ArrayList<>(); 这个love需要改动一下
private  List<ChannelBean> moreChannelBeans =new ArrayList<>();

写完上面的开始这样写

 ///返回图片编辑
   fanhui_layout.setOnClickListener(this);
 bianji_layout.setOnClickListener(this);
  这两个布局需要创建
  cha_view.addHead(View.inflate(this,R.layout.hadel_layout,null));
cha_view.addMore(View.inflate(this,R.layout.gengduo_layout,null)); (两个布局如下)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:padding="10dp"
    android:layout_height="wrap_content"

    >
<TextView
    android:layout_width="wrap_content"
    android:layout_height="60dp"
    android:text="我的频道"
    android:gravity="center"
    />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:padding="10dp"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="70dp"
        android:text="更多频道"
        android:gravity="center"
        />

</RelativeLayout>

随后开始这样for一下

for (int i = 0; i <20 ; i++) {
     if (i  %2==0){
         lovechannelBeans.add(new ChannelBean("头条"+i,i,"url",true));
     }else {
 moreChannelBeans.add(new ChannelBean("昨日"+i,i,"url",false));
     }
} 然后下面用频道管理器的控件这样写一个方法
 cha_view.init(lovechannelBeans, moreChannelBeans, new ChannelView.ChannelCallback() {
      @Override
      public void onMyChannelRemove(ChannelBean channelBean) {
          ////另一个页面跳转 就是上面写的那个Fragment01的跳转,
      }

      @Override
      public void moMoreChannelRemove(ChannelBean channelBean) {

      }
  });
}

然后开始定义编辑器实现拖动返回功能 (定义布尔值)写一个on方法

private  boolean ChanneStar;
   @Override
   public void onClick(View v) {
 switch (v.getId()){
     case R.id.fanhui_layout:
         finish();
         break;
     case R.id.bianji_layout:
         if (!ChanneStar){
             bianji_layout.setText("完成");

         }else {
             bianji_layout.setText("编辑");

         }
         cha_view.changeMyChannelState();
         ChanneStar=!ChanneStar;
         break;
 }
   }

 随后收工完成 

 
 
 

猜你喜欢

转载自blog.csdn.net/qq_41880256/article/details/81227461