码迷,mamicode.com
首页 > 其他好文 > 详细

材料设计---Design

时间:2017-02-07 13:47:10      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:pat   count()   near   int   错误提示   过程   port   支持   mtab   

 

效果:

技术分享

main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<!--CoordinatorLayout:协调者布局。-->
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
        android:id="@+id/teach_appbar"
        android:layout_width="match_parent"
        android:layout_height="260dp">
<!-- app:layout_scrollFlags="scroll|enterAlways"-->
<ImageView android:id="@+id/teach_image" android:layout_width="match_parent" android:layout_height="200dp" android:scaleType="fitXY" android:src="@mipmap/seek" app:layout_scrollFlags="scroll|enterAlways" /> <android.support.design.widget.TabLayout android:id="@+id/teach_tablayout" android:layout_width="match_parent" android:layout_height="60dp" /> </android.support.design.widget.AppBarLayout>
<!--app:layout_behavior="@string/appbar_scrolling_view_behavior" 下面布局仅支持:NestedScrollView和ViewPager --> <android.support.v4.view.ViewPager android:id="@+id/teach_viewpager" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.design.widget.CoordinatorLayout>

 

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/tv_fragment_content"
            android:text="@string/article"
            android:textSize="28sp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

 

/**
 * Design:
 *      TextInputLayout:输入布局,需要嵌套EditText进行使用
 *      TextInputEditText:输入框,可以设置错误提示,
 *      snackBar:加强版的吐司,可以添加点击事件
 *  在开发过程中,要使用一些材料风格的特效,即Design特效
 *  CoordinatorLayout:协调者布局,专门用来处理滑动特效,加强版的FrameLayout
 *  AppBarLayout:专门用来装载导航区域的,非滚动区域。
 *
 */
public class MainActivity extends AppCompatActivity {

    private ViewPager mViewPager;
    private ViewpagerAdapter adapter;
    private TabLayout mTabLaypout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mViewPager = (ViewPager) findViewById(R.id.teach_viewpager);

        adapter = new ViewpagerAdapter(getSupportFragmentManager(),getData());
        mViewPager.setAdapter(adapter);

        mTabLaypout = (TabLayout) findViewById(R.id.teach_tablayout);
        mTabLaypout.setupWithViewPager(mViewPager);
    }

    public List<Fragment> getData() {
        List<Fragment>data=new ArrayList<>();
        for (int i=0;i<4;i++){
            TeachFragment fragment = new TeachFragment();
            data.add(fragment);
        }
        return data;
    }
}

 

public class ViewpagerAdapter extends FragmentPagerAdapter {

    private List<Fragment>data;


    public ViewpagerAdapter(FragmentManager fm,List<Fragment>data) {
        super(fm);
        this.data=data;
    }

    @Override
    public Fragment getItem(int position) {
        return data.get(position);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return "标题"+position;
    }
}

 

public class TeachFragment extends Fragment {
    private View layout;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        layout = inflater.inflate(R.layout.fragment_teach,container,false);
        return layout;
    }
}

 

材料设计---Design

标签:pat   count()   near   int   错误提示   过程   port   支持   mtab   

原文地址:http://www.cnblogs.com/shen-hua/p/5845264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!