Talking about the attributes of android: clipChildren,

Source: Internet
Author: User

Talking about the attributes of android: clipChildren,

Functions:

1. Module bar at the bottom of the APP Main Interface

2. ViewPager is displayed on multiple screens

3 ,........

 

First, you need to understand the meaning of this attribute, that is

Whether to allow a child View to return more than the parent View. Two values are true and false. The default value is true.

When used, set android: clipChildren = "false" for both the child View and the root node View control, so this child View will not be restricted to the parent View.

Bytes -------------------------------------------------------------------------------------------------------------

The following examples are commonly used in two projects:

1. Module bar at the bottom of the APP Main Interface

Set this attribute for the root node control and the Child View that does not want to be restricted by the parent container: android: clipChildren = "false ".

Layout code:

<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: background = "# fff" android: clipChildren = "false" tools: context = "com.xqx.com. treat. ui. user. login "> <LinearLayout android: layout_width =" match_parent "android: layout_height =" 45dp "android: orientation =" horizontal "android: layout_gravity =" bottom "android: background = "# ddd"> <ImageView android: layout_width = "0dp" android: layout_height = "match_parent" android: layout_weight = "1" android: background = "#0000" android: scaleType = "fitCenter" android: src = "@ mipmap/ic_launcher"/> <ImageView android: layout_width = "0dp" android: layout_height = "match_parent" android: layout_weight = "1" android: background = "#0000" android: scaleType = "fitCenter" android: src = "@ mipmap/ic_launcher"/> <ImageView android: layout_width = "0dp" android: layout_height = "65dp" android: layout_weight = "1" android: background = "#0000" android: layout_gravity = "bottom" android: scaleType = "fitCenter" android: src = "@ mipmap/ic_launcher"/> <ImageView android: layout_width = "0dp" android: layout_height = "match_parent" android: layout_weight = "1" android: background = "#0000" android: scaleType = "fitCenter" android: src = "@ mipmap/ic_launcher"/> <ImageView android: layout_width = "0dp" android: layout_height = "match_parent" android: layout_weight = "1" android: background = "#0000" android: scaleType = "fitCenter" android: src = "@ mipmap/ic_launcher"/> </LinearLayout>Main

 

2. Implement scrolling of multiple views on one screen of ViewPager

For details, see the major APP markets and the APP details page. The APP features will be displayed by scrolling similar images.

Android: layout_marginRight = "80dp" android: layout_marginLeft = "80dp"

What are the purposes of setting these two attributes?

First, we can set the width of the ViewPager control

android:layout_width="match_parent"

After we set the distance between the left and right controls, the actual width of ViewPager will be narrowed. The blue box part is the visible part of viewpager.

Note: There is a bug in the method, that is, the View in the middle can only be moved. What if we want to slide the View on the left or right?

Solution: distribute the touch events of the parent class to viewPgaer. R. id. ly is the parent container of the ViewPager control.

findViewById(R.id.ly).setOnTouchListener(new View.OnTouchListener() {            @Override            public boolean onTouch(View v, MotionEvent event) {                return viewpager.dispatchTouchEvent(event);            }        });

In addition, the effect of dynamically setting the spacing for the ViewPager control in the activity code is greatly improved.

viewpager.setPageMargin(8);

ViewPager scroll effect:

ViewPager switching animation (available in Versions later than 3.0)

:

<RelativeLayout 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: paddingLeft = "@ dimen/plugin" android: paddingRight = "@ dimen/plugin" android: paddingTop = "@ dimen/activity_vertical_margin" android: paddingBottom = "@ dimen/plugin" android: background = "# fff" android: id = "@ + id/ly" android: clipChildren = "false" tools: context = "com.xqx.com. treat. viewPagerActivity "> <android. support. v4.view. viewPager android: id = "@ + id/viewpager" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_centerInParent = "true" android: clipChildren = "false" android: layout_marginRight = "80dp" android: layout_marginLeft = "80dp"> </android. support. v4.view. viewPager> </RelativeLayout>View Code

 

Related Article

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.