使用hierarchyviewer查看您的示例,它实现如下:
RelativeLayout保存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>
Run Code Online (Sandbox Code Playgroud)
在Activity的onCreate()方法中添加标题:
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) {}
});
Run Code Online (Sandbox Code Playgroud)
总而言之,您在WearableListView上方有一个View,当滚动ListView时,您只需将标题滚动到视线之外.
再看一下原始问题,anser是:没有布局,提供了,你可以改变.你必须自己做.
希望这可以帮助.
编辑17.09.2014:
如果您希望标题从顶部滚动(如在google示例中),请添加文件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>
Run Code Online (Sandbox Code Playgroud)
以及此代码到您的活动:
@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);
}
}
Run Code Online (Sandbox Code Playgroud)
这应该可以解决问题.
对于那些仍然在看这个的人,我想建立在boun的答案上.onAbsoluteScrollChange现在已弃用,代码应放入其中onScroll.
但是,参数onScroll是自上次onScroll调用以来的变化量,其中参数onAbsoluteScrollChange是滚动后的当前位置; 因此,我们必须稍微修改一下代码.
要解决已弃用的方法,请从中删除代码onAbsoluteScrollChange并执行以下操作:
@Override
public void onScroll(int i) {
header.setY(header.getY() - i);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1717 次 |
| 最近记录: |