The "Disconnected" region is the top empty region thats scrolls up when this listview is scrolled. How do I set layout for that? Thanks.
Looking at your example using the hierarchyviewer it is implemented like this:
A RelativeLayout holds the WearableListView
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/llist"
android:orientation="vertical">
<android.support.wearable.view.WearableListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
In your onCreate() method of the Activity add the header:
public class TestListViewActivity extends Activity implements WearableListView.ClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
RelativeLayout l = (RelativeLayout)findViewById(R.id.llist);
// Below is your header e.g. "disconnected"
// You can do it in code, or you have already defined it in the above xml layout
final TextView header = new TextView(this);
header.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));
final WearableListView listView = (WearableListView)findViewById(R.id.list);
// Add the header, or you have already defined it in the xml layout
l.addView(header, 0);
// Now comes the scrolling part (makes the header disappear)
listView.addOnScrollListener(new WearableListView.OnScrollListener() {
@Override
public void onScroll(int i) {}
@Override
public void onAbsoluteScrollChange(int i) {
// Do only scroll the header up from the base position, not down...
if (i > 0)
header.setY(-i);
}
@Override
public void onScrollStateChanged(int i) {}
@Override
public void onCentralPositionChanged(int i) {}
});
To sum it up, you have a View above the WearableListView and when scrolling the ListView, you simply scroll the header out of sight.
Looking again at the original question, the anser is: There is no layout, that is provided and that you can change. You have to do it yourself.
Hope this helps.
Edit 17.09.2014:
If you want the header to scroll in from the top (as in the google example), add a file res/anim/slidein_top.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="800"
android:fromYDelta="-100%"
android:toYDelta="0%" />
</set>
and this code to your activity:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if(hasFocus){
RelativeLayout l = (RelativeLayout)findViewById(R.id.llist);
final Animation slide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidein_top);
// find the header or cache it elsewhere
l.getChildAt(0).startAnimation(slide);
}
}
This should do the trick.
For those of you still looking at this, I would like to build on boun's answer. onAbsoluteScrollChange
is now deprecated and the code should be put into onScroll
, instead.
However, the parameter of onScroll
is the amount of change since the last time onScroll
was called, where as the parameter of onAbsoluteScrollChange
is the current position after the scroll; therefore, we must modify the code a little.
To work around the deprecated method, remove the code from onAbsoluteScrollChange
and do the following:
@Override
public void onScroll(int i) {
header.setY(header.getY() - i);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With