Search in sources :

Example 36 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project dynamic-load-apk by singwhatiwanna.

the class MainActivity method generateContentView.

private View generateContentView(final Context context) {
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    layout.setBackgroundColor(Color.parseColor("#F79AB5"));
    Button button = new Button(context);
    button.setText("Start TestActivity");
    layout.addView(button, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            DLIntent intent = new DLIntent(getPackageName(), TestFragmentActivity.class);
            // 传递Parcelable类型的数据
            intent.putExtra("person", new Person("plugin-a", 22));
            intent.putExtra("dl_extra", "from DL framework");
            startPluginActivityForResult(intent, 0);
        }
    });
    Button button2 = new Button(context);
    button2.setText("Start Service");
    layout.addView(button2, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    button2.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            DLIntent intent = new DLIntent(getPackageName(), TestService.class);
            startPluginService(intent);
        }
    });
    Button button3 = new Button(context);
    button3.setText("bind Service");
    layout.addView(button3, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    button3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mConnecton == null) {
                mConnecton = new ServiceConnection() {

                    public void onServiceDisconnected(ComponentName name) {
                    }

                    public void onServiceConnected(ComponentName name, IBinder binder) {
                        int sum = ((ITestServiceInterface) binder).sum(5, 5);
                        Log.e("MainActivity", "onServiceConnected sum(5 + 5) = " + sum);
                    }
                };
            }
            DLIntent intent = new DLIntent(getPackageName(), TestService.class);
            bindPluginService(intent, mConnecton, Context.BIND_AUTO_CREATE);
        }
    });
    Button button4 = new Button(context);
    button4.setText("unbind Service");
    layout.addView(button4, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    button4.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            if (mConnecton != null) {
                DLIntent intent = new DLIntent(getPackageName(), TestService.class);
                unBindPluginService(intent, mConnecton);
                mConnecton = null;
            }
        }
    });
    return layout;
}
Also used : ServiceConnection(android.content.ServiceConnection) LayoutParams(android.view.ViewGroup.LayoutParams) View(android.view.View) IBinder(android.os.IBinder) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) ComponentName(android.content.ComponentName) ITestServiceInterface(com.ryg.dynamicload.service.ITestServiceInterface) DLIntent(com.ryg.dynamicload.internal.DLIntent) LinearLayout(android.widget.LinearLayout)

Example 37 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project platform_frameworks_base by android.

the class FastScroller method createPreviewTextView.

/**
     * Creates a view into which preview text can be placed.
     */
private TextView createPreviewTextView(Context context) {
    final LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    final TextView textView = new TextView(context);
    textView.setLayoutParams(params);
    textView.setSingleLine(true);
    textView.setEllipsize(TruncateAt.MIDDLE);
    textView.setGravity(Gravity.CENTER);
    textView.setAlpha(0f);
    // Manually propagate inherited layout direction.
    textView.setLayoutDirection(mList.getLayoutDirection());
    return textView;
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams)

Example 38 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project platform_frameworks_base by android.

the class DayPickerViewPager method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    populate();
    // Everything below is mostly copied from FrameLayout.
    int count = getChildCount();
    final boolean measureMatchParentChildren = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY || MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY;
    int maxHeight = 0;
    int maxWidth = 0;
    int childState = 0;
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            measureChild(child, widthMeasureSpec, heightMeasureSpec);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            maxWidth = Math.max(maxWidth, child.getMeasuredWidth());
            maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
            childState = combineMeasuredStates(childState, child.getMeasuredState());
            if (measureMatchParentChildren) {
                if (lp.width == LayoutParams.MATCH_PARENT || lp.height == LayoutParams.MATCH_PARENT) {
                    mMatchParentChildren.add(child);
                }
            }
        }
    }
    // Account for padding too
    maxWidth += getPaddingLeft() + getPaddingRight();
    maxHeight += getPaddingTop() + getPaddingBottom();
    // Check against our minimum height and width
    maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
    maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
    // Check against our foreground's minimum height and width
    final Drawable drawable = getForeground();
    if (drawable != null) {
        maxHeight = Math.max(maxHeight, drawable.getMinimumHeight());
        maxWidth = Math.max(maxWidth, drawable.getMinimumWidth());
    }
    setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), resolveSizeAndState(maxHeight, heightMeasureSpec, childState << MEASURED_HEIGHT_STATE_SHIFT));
    count = mMatchParentChildren.size();
    if (count > 1) {
        for (int i = 0; i < count; i++) {
            final View child = mMatchParentChildren.get(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            final int childWidthMeasureSpec;
            final int childHeightMeasureSpec;
            if (lp.width == LayoutParams.MATCH_PARENT) {
                childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth() - getPaddingLeft() - getPaddingRight(), MeasureSpec.EXACTLY);
            } else {
                childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width);
            }
            if (lp.height == LayoutParams.MATCH_PARENT) {
                childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight() - getPaddingTop() - getPaddingBottom(), MeasureSpec.EXACTLY);
            } else {
                childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom(), lp.height);
            }
            child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
        }
    }
    mMatchParentChildren.clear();
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) Drawable(android.graphics.drawable.Drawable) View(android.view.View)

Example 39 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project platform_frameworks_base by android.

the class ResizingSpace method onConfigurationChanged.

@Override
protected void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    LayoutParams params = getLayoutParams();
    boolean changed = false;
    if (mWidth > 0) {
        int width = getContext().getResources().getDimensionPixelOffset(mWidth);
        if (width != params.width) {
            params.width = width;
            changed = true;
        }
    }
    if (mHeight > 0) {
        int height = getContext().getResources().getDimensionPixelOffset(mHeight);
        if (height != params.height) {
            params.height = height;
            changed = true;
        }
    }
    if (changed) {
        setLayoutParams(params);
    }
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams)

Example 40 with LayoutParams

use of android.view.ViewGroup.LayoutParams in project androidquery by androidquery.

the class AbstractAQuery method margin.

/**
	 * Set the margin of a view. Notes all parameters are in DIP, not in pixel.
	 *
	 * @param leftDip the left dip
	 * @param topDip the top dip
	 * @param rightDip the right dip
	 * @param bottomDip the bottom dip
	 * @return self
	 */
public T margin(float leftDip, float topDip, float rightDip, float bottomDip) {
    if (view != null) {
        LayoutParams lp = view.getLayoutParams();
        if (lp instanceof MarginLayoutParams) {
            Context context = getContext();
            int left = AQUtility.dip2pixel(context, leftDip);
            int top = AQUtility.dip2pixel(context, topDip);
            int right = AQUtility.dip2pixel(context, rightDip);
            int bottom = AQUtility.dip2pixel(context, bottomDip);
            ((MarginLayoutParams) lp).setMargins(left, top, right, bottom);
            view.setLayoutParams(lp);
        }
    }
    return self();
}
Also used : Context(android.content.Context) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) LayoutParams(android.view.ViewGroup.LayoutParams) MarginLayoutParams(android.view.ViewGroup.MarginLayoutParams) Paint(android.graphics.Paint)

Aggregations

LayoutParams (android.view.ViewGroup.LayoutParams)263 TextView (android.widget.TextView)54 View (android.view.View)50 ViewGroup (android.view.ViewGroup)50 FrameLayout (android.widget.FrameLayout)35 LinearLayout (android.widget.LinearLayout)32 ImageView (android.widget.ImageView)30 Test (org.junit.Test)26 ListView (android.widget.ListView)22 ScrollView (android.widget.ScrollView)22 Paint (android.graphics.Paint)21 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)19 Context (android.content.Context)18 AdapterView (android.widget.AdapterView)17 RelativeLayout (android.widget.RelativeLayout)14 DisplayMetrics (android.util.DisplayMetrics)12 CheckedTextView (android.widget.CheckedTextView)12 Rect (android.graphics.Rect)9 ViewParent (android.view.ViewParent)9 TypedArray (android.content.res.TypedArray)8