0

我正在使用以下代码以编程方式创建开关:

Switch s = new Switch(mActivity);

s.setText(text);
s.setBackground(selectorDrawable);       
s.setTypeface(mFont);
s.setTextSize(mEntriesTextSize);
s.setTextSize(8);
s.setTag(command);
s.setVisibility(View.VISIBLE);
s.setPadding(mEntriesSidesPadding,
    mEntriesUpDownPadding, mEntriesSidesPadding,
    mEntriesUpDownPadding);
s.setChecked(on);

// attempted to change height here...

s.setOnCheckedChangeListener(mOnCheckedListener);

mLayout.addView(s, mLayoutParams);
returnView = s;

我该如何改变屏幕上实际开关的高度(不是文本高度,ON/OFF 开关本身的高度)

我试过了

setMaxHeight(), setMinHeight(), setHeight()

但似乎没有任何效果。

4

2 回答 2

0

效果最好的解决方案是:

            s.setSwitchMinWidth(x);

x你想要的价值在哪里。我花了一段时间才在上述类似功能中找到它。

于 2015-01-06T12:35:46.613 回答
0

您可以使用:

s.getLayoutParams().height = YOUR_HEIGHT;

(YOUR_HEIGHT 是所需的像素高度)

如果您在布局已经“布局”后设置高度,请确保调用:

s.requestLayout()
于 2015-01-06T12:00:01.163 回答