QuickReturn
QuickReturn copied to clipboard
Blank area displays under target view as you scroll up
Hi. Is there a way to prevent the blank area on the target view (as you scroll up) or is this is an existing issue (I didn't see it in the issues list)? I've tried setting the target view's height as not only 0, but other +/- values, as well. I've also tried leaving it off, but the issue persists. Please help. Hopefully there is an easy fix. This library is great, otherwise. Thank you!
Here is a video demonstrating the issue.
Here is my code:
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>
onCreate in MainActivity.java
@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);
}
}
Note: getListData()
just returns List<StudentMenuItem>
to populate the list.
I have the same problem. Have you solved it yet?
No. We decided to switch to a different implementation.
Could you tell me which one? I'm also looking for an alternative one. Thanks!
Sorry for the late response. We had to write our own implementation due to time constraints, but I would like to share a solution I partially received from Stack Overflow and something I discovered - this is based on my implementation above:
In activity_main.xml:
- Move the TextView below the ListView
- Set android:layout_gravity="bottom" on the ListView
- Change the LinearLayout to a FrameLayout