我有一个preferenceFragment子类。我想其项目(preferences和开关preferences)中的每一个以具有120dp的高度。那怎么办?
I have a PreferenceFragment subclass. I want each one of its items (Preferences and SwitchPreferences) to have a height of 120dp. How to do that?
下面是相关的code:
Here is the related code:
public class SettingsFragment extends PreferenceFragment {
public SettingsFragment() {}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.main);
}
}
和
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference android:key="app_main_switch"
android:title="@string/app_name"
android:defaultValue="true"/>
<Preference android:title="@string/events_lowercase"
android:dependency="app_main_switch">
<intent android:targetPackage="hu.ppke.itk.marma.android.bead"
android:targetClass="hu.ppke.itk.marma.android.bead.EventList"/>
</Preference>
<Preference android:title="@string/filters_lowercase"
android:dependency="app_main_switch">
<intent android:targetPackage="hu.ppke.itk.marma.android.bead"
android:targetClass="hu.ppke.itk.marma.android.bead.FilterList"/>
</Preference>
<SwitchPreference android:dependency="app_main_switch"
android:key="learn_switch"
android:defaultValue="false"
android:title="@string/learning"/>
</PreferenceScreen>
下面是如何看起来像现在:
Here is how it looks like now:
所以,我希望所有四个项目名单有120dp的高度。正如你所看到的,我不是一个创造的ListView,它的内部创建的。我试图用
So I want all four items of the list to have a height of 120dp. As you can see I'm not the one creating the ListView, it's created internally. I tried to retrieve it with
findViewById(android.R.id.list)
但迭代它的元素给preference对象不容许我设置的高度。
but iterating over its elements gives Preference objects which do not allow me to set the height.
下面是我如何成功地做到这一点:
Here is how I managed to do this:
我也需要继承preference但MattMatt的回答没有工作。
I did need to subclass Preference but MattMatt's answer didn't work.
public class HigherPreference extends Preference {
public HigherPreference(Context context) {
super(context);
}
public HigherPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View onCreateView(ViewGroup parent) {
Resources res=getContext().getResources();
View v=super.onCreateView(parent);
v.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, res.getDimensionPixelSize(R.dimen.rowheight)));
return v;
}
}
布局XML是这样,他提供了什么。
The layout XML goes like what he provided.
上一篇:如何使一个&QUOT;不要再&QUOT问我;对话框弹出框?安卓问我、弹出、不要再、对话框
下一篇:机器人:NeighboringCellInfo总是空的!?为什么?机器人、NeighboringCellInfo