我正在使用QuickReturn,在向上滚动时,目标视图后面有一个空白区域。
有没有办法防止目标视图上的空白区域(向上滚动)或这是一个现有问题(我没有在问题列表中看到它,但我已将其作为错误提交)?
我已经尝试将目标视图的高度设置为不仅是0,还有其他+/-值。我也尝试过了; e.g:
qrAttacher.addTargetView(testTextView, QuickReturnTargetView.POSITION_TOP, -1);
qrAttacher.addTargetView(testTextView, QuickReturnTargetView.POSITION_TOP, 0);
qrAttacher.addTargetView(testTextView, QuickReturnTargetView.POSITION_TOP, 50);
qrAttacher.addTargetView(testTextView, QuickReturnTargetView.POSITION_TOP);
......但问题仍然存在。
以下a video证明了这个问题。
以下是a video应该做的事情。
如果视频出现问题,这里有一系列图片展示了向上滚动时会发生什么:
这是我的代码:
activity_main.xml中
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/testTextView"
android:layout_width="match_parent"
android:layout_height="90dp"
android:paddingLeft="10dp"
android:gravity="center_vertical"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@android:color/white"
android:background="@android:color/black"
android:textStyle="bold"
android:text="Test Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_light"/>
</LinearLayout>
act_student_menu_item.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/studentMenuContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="8dp"
android:layout_centerVertical="true"
android:orientation="horizontal">
<ImageView
android:id="@+id/studentPhotoIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:src="@drawable/icon_photo_grey" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/studentPhotoIcon"
android:layout_centerInParent="true"
android:orientation="vertical">
<TextView
android:id="@+id/studentNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textColor="@android:color/white"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/studentPointsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textColor="@android:color/white"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
在MainActivity.java中创建onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// The list view to show/hide on scroll.
ListView listView = (ListView) findViewById(android.R.id.list);
TextView testTextView = (TextView) findViewById(R.id.testTextView);
TestAdapter testAdapter = new TestAdapter(this, android.R.layout.simple_spinner_item,
getListData());
// Wrap the adapter with QuickReturnAdapter.
listView.setAdapter(new QuickReturnAdapter(testAdapter));
// Attach QuickReturn Attacher, which takes care of all of the hide/show functionality.
QuickReturnAttacher qrAttacher = QuickReturnAttacher.forView(listView);
/**
* Add a quick return targetView to the attacher.
* You can pass a position argument (POSITION_TOP or POSITION_BOTTOM). You can also optionally pass the size of
* the target view, which will be used to offset the list height, preventing it from hiding content behind the
* target view.
*/
qrAttacher.addTargetView(testTextView, QuickReturnTargetView.POSITION_TOP, 0);
}
TestAdapter.java
public class TestAdapter extends ArrayAdapter<StudentMenuItem> {
private final Context currentContext;
private List<StudentMenuItem> studentMenuItems;
ImageView studentPhotoIcon;
TextView studentNameText;
public TestAdapter(Context context, int layoutResourceId, List<StudentMenuItem> studentMenuItems) {
super(context, layoutResourceId, studentMenuItems);
currentContext = context;
this.studentMenuItems = studentMenuItems;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
View studentMenuOption = convertView;
if (studentMenuOption == null) {
LayoutInflater inflater = (LayoutInflater) currentContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
studentMenuOption = inflater.inflate(R.layout.act_student_menu_item, parent, false);
}
StudentMenuItem current = studentMenuItems.get(position);
studentNameText = (TextView) studentMenuOption.findViewById(R.id.studentNameText);
studentNameText.setText(current.getStudentName());
TextView studentPointsText = (TextView) studentMenuOption.findViewById(R.id.studentPointsText);
studentPointsText.setText(current.getStudentPoints());
studentPhotoIcon = (ImageView) studentMenuOption.findViewById(R.id.studentPhotoIcon);
return studentMenuOption;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return getDropDownView(position, convertView, parent);
}
}
注意:getListData()
只需返回List<StudentMenuItem>
即可填充列表。
请帮忙。希望有一个简单的解决方案。谢谢。
答案 0 :(得分:0)
您应该在ListView
之后找到目标视图(Test Title TextView)答案 1 :(得分:0)
(由于对这篇文章的回复只是部分解决方案,我用完整的解决方案发布了答案。)
在activity_main.xml中: