本文整理匯總了Java中android.support.v7.widget.SwitchCompat.setLayoutParams方法的典型用法代碼示例。如果您正苦於以下問題:Java SwitchCompat.setLayoutParams方法的具體用法?Java SwitchCompat.setLayoutParams怎麽用?Java SwitchCompat.setLayoutParams使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.SwitchCompat
的用法示例。
在下文中一共展示了SwitchCompat.setLayoutParams方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import android.support.v7.widget.SwitchCompat; //導入方法依賴的package包/類
@Override
public void init() {
super.init();
mSwitch = new SwitchCompat(getContext()) {
boolean isTouched = false;
@Override
public void setChecked(boolean checked) {
if ( isTouched || mForced ) {
super.setChecked(checked);
if ( isTouched && mListener != null ) {
isTouched = false;
mListener.onCheckedChanged(this, checked);
}
mForced = false;
}
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
isTouched = true;
return super.onTouchEvent(ev);
}
};
mSwitch.setId(R.id.settings_switch);
RelativeLayout.LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
mSwitch.setLayoutParams(lp);
lp = (LayoutParams) mTextView.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
lp.addRule(RelativeLayout.LEFT_OF, mSwitch.getId());
mTextView.setLayoutParams(lp);
int p = getResources().getDimensionPixelOffset(R.dimen.eight_dp) / 4;
mSwitch.setPadding(p, p, p, p);
addView(mSwitch);
}