我有一个ScrollView如下:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/filtersDialogPreference_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<CheckBox
android:id="@+id/filtersDialogPreference_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
使用上面的XML的对应类
public class FiltersDialogPreference extends DialogPreference implements OnClickListener{
public FiltersDialogPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setPersistent(false);
mContext = context;
}
@Override
public void onBindDialogView(View view) {
super.onBindDialogView(view);
}
@Override
protected View onCreateDialogView() {
LinearLayout layout = null;
filters = new ArrayList<Filter>();
checkboxes = new ArrayList<CheckBox>();
LayoutInflater mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = (LinearLayout) mInflater.inflate(R.layout.filter_dialog_preference, null, false);
FiltersDataSource ds = new FiltersDataSource(mContext);
ds.open();
// read the current filter preferences
ArrayList<String> ids = ds.getFilterIDs();
View filterView;
for (int i = 0; i < ids.size(); i++) {
String name = ds.getFilter(ids.get(i)).getFilterName();
boolean isMonitored = ds.isMonitored(ids.get(i));
filters.add(new Filter(ids.get(i), name, isMonitored));
filterView = mInflater.inflate(R.layout.filter_selection_item, null);
TextView nametv = (TextView) filterView.findViewById(R.id.filtersDialogPreference_textView);
nametv.setText(name);
CheckBox checkBox = (CheckBox) filterView.findViewById(R.id.filtersDialogPreference_checkbox);
checkBox.setOnClickListener(this);
checkBox.setChecked(isMonitored);
checkboxes.add(checkBox);
layout.addView(filterView);
}
ds.close();
return layout;
}
@Override
public void onDialogClosed(boolean positiveResult) {
if (positiveResult) {
Log.v(GSGUIConst.LOG_DEV, "Saving filter settings");
FiltersDataSource ds = new FiltersDataSource(mContext);
ds.open();
for (int i = 0; i < filters.size(); i++) {
String _id = filters.get(i).mID;
boolean enabled = filters.get(i).isEnabled();
ds.setMonitoredValue(_id, enabled);
//Log.v(GSGUIConst.LOG_DEV, "reread"+ds.getFilter(_id).getFilterName()+": "+ds.isMonitored(_id));
}
ds.close();
}
}
private class Filter {
private String mName;
private boolean mEnabled;
private String mID;
public Filter(String _id, String name, boolean enabled) {
mID = _id;
mName = name;
mEnabled = enabled;
}
public String getID() {
return mID;
}
public boolean isEnabled() {
return mEnabled;
}
public void setEnabled(boolean monitored) {
mEnabled = monitored;
}
public String toString() {
return mName;
}
}
@Override
public void onClick(View v) {
CheckBox checkBox = (CheckBox)v;
int id = checkboxes.indexOf(checkBox);
filters.get(id).setEnabled(checkBox.isChecked());
}
}
此设置Activity上有很多条目,但不幸的是布局对滚动没有反应。任何的想法? 我不确定是否有必要使用ScrollView。 LinearLayout也应该处理滚动,不应该吗?
答案 0 :(得分:0)
在xml
中设置它android:maxLines = "100"
android:scrollbars = "vertical"
然后在你的活动onCreate:
中使用它TextView yourTextView = (TextView) findViewById (R.Id.textview1)
yourTextView.setMovementMethod(new ScrollingMovementMethod())
答案 1 :(得分:0)
这是因为您将ScrollView的高度设置为wrap_content。尝试给它一个固定的高度或使用一个有重量的LinearLayout,这样它就可以填充其他视图留下的空间。