1. 程式人生 > >頻道管理(tablayout)

頻道管理(tablayout)

主頁面(還有兩個頁面}(佈局)\

//依賴

implementation 'channelmanager:channelmanager:0.4.8'

專案的build.gradle中新增

repositories {
    google()
    jcenter()
   只有這一行 maven { url 'https://dl.bintray.com/bruceanda/maven/' }
}
package com.bwei.Xmu;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawei.channelmanager.bean.ChannelBean;
import com.bawei.channelmanager.ui.ChannelView;


import java.util.ArrayList;
import java.util.List;

public class Channel1Activity extends AppCompatActivity implements View.OnClickListener {

    private ImageView iv_image;
    private TextView tv_edit;
    private ChannelView chanel_view;
    // 存放頻道的List
    private List<ChannelBean> loveChannel = new ArrayList<>();
    private List<ChannelBean> moreChannel = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_channe);
        initView();
        iv_image.setOnClickListener(this);
        tv_edit.setOnClickListener(this);

        chanel_view.addHead(View.inflate(this,R.layout.layout_haner,null));
        chanel_view.addMore(View.inflate(this,R.layout.layout_font,null));
        //初始化資料
        for (int i = 0; i <20;i++) {
            if (i%2==0){
                    loveChannel.add(new ChannelBean("娛樂"+i,i,"http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1",true));
            }else{
                moreChannel.add(new ChannelBean("娛樂"+i,i,"http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1",false));

            }

        }
        chanel_view.init(loveChannel, moreChannel, new ChannelView.ChannelCallback() {
            @Override
            public void onMyChannelRemove(ChannelBean channelBean) {

            }

            @Override
            public void moMoreChannelRemove(ChannelBean channelBean) {

            }
        });



    }

    private void initView() {
        iv_image = (ImageView) findViewById(R.id.iv_image);
        tv_edit = (TextView) findViewById(R.id.tv_edit);
        chanel_view = (ChannelView) findViewById(R.id.chanel_view);
    }
    private boolean channelState;
    @Override
    public void onClick(View v) {
        switch (v.getId()){

            case R.id.iv_image:
                finish();
                break;
            case R.id.tv_edit:
                if (!channelState){
                    tv_edit.setText("完成");

                }else{

                    tv_edit.setText("編輯");
                }
                chanel_view.changeMyChannelState();
                channelState=!channelState;
                break;
        }
    }
}
<?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="50dp"
        android:background="@drawable/ic_launcher_background">

        <ImageView
            android:id="@+id/iv_image"
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:padding="10dp"
            android:src="@drawable/ic_fanhui_24dp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="頻道管理"
            android:textAppearance="@android:style/TextAppearance.StatusBar.Title"
            android:textColor="@android:color/white" />

        <TextView
            android:id="@+id/tv_edit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:text="編輯"
            android:textColor="@android:color/black" />

    </LinearLayout>

    <com.bawei.channelmanager.ui.ChannelView
        android:id="@+id/chanel_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!--<CalendarView-->
    <!--android:layout_width="match_parent"-->
    <!--android:layout_height="match_parent"></CalendarView>-->


</LinearLayout>

我的頻道
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:gravity="center"
        android:text="我的頻道"
        android:textAppearance="@android:style/TextAppearance.Holo.Medium" />
</RelativeLayout>
更多頻道(和我的頻道一樣)

java程式碼

package com.bwei.Xmu;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bawei.channelmanager.bean.ChannelBean;
import com.bawei.channelmanager.ui.ChannelView;


import java.util.ArrayList;
import java.util.List;

public class Channel1Activity extends AppCompatActivity implements View.OnClickListener {

    private ImageView iv_image;
    private TextView tv_edit;
    private ChannelView chanel_view;
    // 存放頻道的List
    private List<ChannelBean> loveChannel = new ArrayList<>();
    private List<ChannelBean> moreChannel = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_channe);
        initView();
        iv_image.setOnClickListener(this);
        tv_edit.setOnClickListener(this);

        chanel_view.addHead(View.inflate(this,R.layout.layout_haner,null));
        chanel_view.addMore(View.inflate(this,R.layout.layout_font,null));
        //初始化資料
        for (int i = 0; i <20;i++) {
            if (i%2==0){
                    loveChannel.add(new ChannelBean("娛樂"+i,i,"http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1",true));
            }else{
                moreChannel.add(new ChannelBean("娛樂"+i,i,"http://gank.io/api/data/%E7%A6%8F%E5%88%A9/10/1",false));

            }

        }
        chanel_view.init(loveChannel, moreChannel, new ChannelView.ChannelCallback() {
            @Override
            public void onMyChannelRemove(ChannelBean channelBean) {

            }

            @Override
            public void moMoreChannelRemove(ChannelBean channelBean) {

            }
        });



    }

    private void initView() {
        iv_image = (ImageView) findViewById(R.id.iv_image);
        tv_edit = (TextView) findViewById(R.id.tv_edit);
        chanel_view = (ChannelView) findViewById(R.id.chanel_view);
    }
    private boolean channelState;
    @Override
    public void onClick(View v) {
        switch (v.getId()){

            case R.id.iv_image:
                finish();
                break;
            case R.id.tv_edit:
                if (!channelState){
                    tv_edit.setText("完成");

                }else{

                    tv_edit.setText("編輯");
                }
                chanel_view.changeMyChannelState();
                channelState=!channelState;
                break;
        }
    }
}