OSC android app LayoutParams改进

android.view.ViewGroup.LayoutParams

public static final int FILL_PARENT

Since: API Level 1

Special value for the height or width requested by a View. FILL_PARENT means that the view wants to be as big as its parent, minus the parent's padding, if any. This value is deprecated starting in API Level 8 and replaced by MATCH_PARENT.

Constant Value: -1 (0xffffffff)

////////////////////////////////////////////////////

private void applyTo(View target) {

       
        LayoutParams lp = target.getLayoutParams();
        ViewParent parent = target.getParent();
        FrameLayout container = new FrameLayout(context);
       
        if (target instanceof TabWidget) {
           
            // set target to the relevant tab child container
            target = ((TabWidget) target).getChildTabViewAt(targetTabIndex);
            this.target = target;
           

            ((ViewGroup) target).addView(container,

                    new LayoutParams(LayoutParams. MATCH_PARENT, LayoutParams.MATCH_PARENT));

                    //new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

           最好是根据版本来  Build.VERSION.SDK_INT;

请参考:

As described in the android documentation, the SDK level (integer) the phone is running is available in:

android.os.Build.VERSION.SDK_INT;

The enum corresponding to this int is in the android.os.Build.VERSION_CODES class.

Code example:

int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO){     // Do something for froyo and above versions } else{     // do something for phones running an SDK before froyo } 

Edit: This SDK_INT is available since Donut (android 1.6 / API4) so make sure your application is not retro-compatible with Cupcake (android 1.5 / API3) when you use it or your application will crash (thanks to Programmer Bruce for the precision).

Corresponding android documentation:

http://developer.android.com/reference/android/os/Build.VERSION.html#SDK_INT

http://developer.android.com/reference/android/os/Build.VERSION_CODES.html

你可能感兴趣的:(OSC android app LayoutParams改进)