Material Design-design, Design-design

Source: Internet
Author: User

Material Design-design, Design-design

 

Effect:

Main_activity.xml

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- CoordinatorLayout: Coordinator layout. --> <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" The following layout is only supported: NestedScrollView and 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: Enter the layout. You need to nest EditText to use * TextInputEditText: input box. You can set an error message. * snackBar: enhanced toast, you can add click events * during development, you need to use some material-style special effects, that is, Design special effects * CoordinatorLayout: The CoordinatorLayout, which is used to handle sliding special effects. The enhanced version of FrameLayout * AppBarLayout: A non-rolling area dedicated for loading navigation areas. **/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 "title" + 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;    }}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.