Вы можете переопределить getView(View, ViewGroup)
в своем предпочтении.Затем отправьте new LayoutParams
на getView()
.Я попробовал это с настроенным CheckBoxPreference.Отлично работает.
import android.content.Context;
import android.preference.CheckBoxPreference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView.LayoutParams;
public class CustomCheckBoxPreference extends CheckBoxPreference {
public CustomCheckBoxPreference(final Context context, final AttributeSet attrs,
final int defStyle) {
super(context, attrs, defStyle);
}
public CustomCheckBoxPreference(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public CustomCheckBoxPreference(final Context context) {
super(context);
}
@Override
public View getView(final View convertView, final ViewGroup parent) {
final View v = super.getView(convertView, parent);
final int height = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
final int width = 300;
final LayoutParams params = new LayoutParams(height, width);
v.setLayoutParams(params );
return v;
}
}
Просто будьте осторожны, используйте правильные LayoutParams для View, иначе вы можете получить исключение приведения класса.