在我的应用程序的一个屏幕中,我有一个没有响应手势的ListFragment。在其他屏幕中,我的ListFragments表现得恰当 - 根据触摸向上和向下移动。但是这个实例不会响应手势而移动。我已经尝试将高度设置为特定的倾角,将ListFragment包含在ScrollView中但没有任何效果。日志证明列表中有3个条目,但只有第一个和第二个条目可见。我可以从列表中选择第一个条目。
xml如下。它是由"标识的内部片段。机器人:名称=" com.chex.control.LabelList""那不是滚动。
有没有人遇到过这个问题并解决了?
由于
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/new_interval_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Interval" />
<EditText
android:id="@+id/days_in_interval"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="days in interval"
android:inputType="number"
android:singleLine="true" />
<EditText
android:id="@+id/goodi_goal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="goodi goal"
android:inputType="number"
android:singleLine="true" />
<LinearLayout
android:id="@+id/label_selector"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/default_label_pane"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Default Labels" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" >
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/default_labels_fragment"
android:name="com.chex.control.LabelList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:focusable="true" >
</fragment>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="@+id/add_remove_label_selector"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="@+id/add_label_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add" />
<Button
android:id="@+id/remove_label_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Remove" />
</LinearLayout>
<LinearLayout
android:id="@+id/label_pane"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Inteval Labels" />
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/interval_labels_fragment"
android:name="com.chex.control.IntervalLabelList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true" >
</fragment>
<EditText
android:id="@+id/new_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="new label"
android:inputType="text"
android:singleLine="true" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/keep_discard_button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/keep_interval_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Keep" />
<Button
android:id="@+id/discard_interval_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Discard" />
</LinearLayout>
</LinearLayout>
</ScrollView>
这里是片段.java
package com.chex.control;
import java.util.ArrayList;
import com.chex.R;
import com.chex.storage.Child;
import com.chex.storage.DatabaseConstants;
import com.chex.storage.DatabaseHelper;
import com.chex.storage.DatabaseIO;
import com.chex.storage.Label;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
/**
* presents all the labels on the device.
*/
public class LabelList extends ListFragment implements DatabaseConstants,
GoodiList {
private final String TAG = "LabelList";
ArrayAdapter<Label> adapter = null;
private ListParent parentActivity;
private Label[] values;
private Label currentItem;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e(TAG, "on Create");
ArrayList<Label> labelList = Label.getLabelsForInterval();
Log.i(TAG,labelList.size()+" labels");
// adapter = new IntervalListAdapter(getActivity(), values);
adapter = new IntervalListAdapter(getActivity(), labelList);
setListAdapter(adapter);
Log.e(TAG, "finished on Create");
}
/*
* (non-Javadoc)
*
* @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
*/
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
LongClickListener longClickListener = new LongClickListener();
getListView().setOnItemLongClickListener(longClickListener);
}
/**
* create and return a CursorLoader that will take care of creating a Curso
* for the data being displayed.
*/
/**
* this used to delete. However, we need it to select usually. Now delete is
* done by long click.
*/
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// delete child - remove child from list and database
Object item = l.getItemAtPosition(position);
currentItem = (Label) item;
Log.e(TAG,
"selected " + currentItem.getLabel() + " id: "
+ currentItem.getId() + " at position " + position);
parentActivity.listItemSelected(this, position, currentItem.getId());
}
/**
* Forces cursor to requery database and list to be update. Used when a new
* child is entered in parent activity's EditText field.
*/
public void notifyDataChanged() {
Log.e(TAG, "told adapter that data changed");
adapter.notifyDataSetChanged();
}
/*
* (non-Javadoc)
*
* @see android.support.v4.app.Fragment#onAttach(android.app.Activity)
*/
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
parentActivity = (ListParent) activity;
parentActivity.setList(this);
}
class LongClickListener implements OnItemLongClickListener {
public boolean onItemLongClick(AdapterView<?> adapterView, View view,
int position, long id) {
// delete child - remove child from list and database
// adapter view. Can always call parent's getItemAtPosition
final Object item = adapterView.getItemAtPosition(position);
final Label label = (Label) item;
final String name = label.getLabel();
Log.e(TAG, "selected " + name + " at position " + position
+ " now we'll delete them");
// make sure user wants to delete
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle("Delete " + name + "?");
alert.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Label.deleteLabel(name);
adapter.remove(label);
// update the list
notifyDataChanged();
}
});
alert.setNegativeButton("No",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// nothing happens - child remains
}
});
alert.show();
return true;
}
}
@Override
public void addListItem(int itemId) {
Label labelToAdd = Label.lookupLabel(itemId);
if (labelToAdd == null) {
Log.e(TAG, "didn't find a label for label id " + itemId);
} else {
Log.e(TAG, "adding label: " + labelToAdd.getLabel() + " "
+ labelToAdd.getId() + " id argument: " + itemId);
// breaks because the adapter is currently strings
adapter.add(labelToAdd);
notifyDataChanged();
}
}
@Override
public void removeListItem(int itemId) {
// TODO Auto-generated method stub
}
@Override
public void removeListItem() {
// TODO Auto-generated method stub
}
@Override
public void highlightListIndex(int index) {
ListView listView = getListView();
listView.setItemChecked(index, true);
}
}
答案 0 :(得分:0)
在滚动视图中滚动视图时,android不是最好的,就像你的情况一样。 您必须尝试避免这种情况,尝试修改布局以避免这些冲突。
a **方法的一个难点是拦截父母的触摸事件(也添加一个手势监听器)并在用户在listfragment上进行滚动时将事件传递给listfragment(你必须知道屏幕内的片段等)。这听起来要容易得多,之后会引起很多问题,所以我建议改写你的布局。