如何在WearableListView中设置topEmptyRegion的布局?
如何在WearableListView中设置topEmptyRegion的布局?,listview,wear-os,Listview,Wear Os,“断开连接”区域是滚动此列表视图时向上滚动的顶部空白区域。如何设置布局?谢谢。使用hierarchyviewer查看您的示例,其实现方式如下: RelativeLayout持有WearableListView <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="f
“断开连接”区域是滚动此列表视图时向上滚动的顶部空白区域。如何设置布局?谢谢。使用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>
总而言之,您在WearableListView上方有一个视图,当滚动ListView时,您只需将标题滚动到看不见的地方
再看看原来的问题,答案是:没有布局,它是提供的,您可以更改。你必须自己做
希望这有帮助
编辑2014年9月17日:
如果要从顶部滚动标题(如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>
这应该可以解决问题。对于那些仍在关注这一问题的人,我想以boun的答案为基础
OnAbsolutionScrollChange
现在已不推荐使用,而应将代码放入onScroll
但是,onScroll
的参数是自上次调用onScroll
以来的更改量,其中,onabsolutionscrollchange
的参数是滚动后的当前位置;因此,我们必须稍微修改代码
要解决不推荐使用的方法,请从OnAbsolutionScrollChange中删除代码,然后执行以下操作:
@Override
public void onScroll(int i) {
header.setY(header.getY() - i);
}
我张贴了完整的工作和简单的例子。。看看这个 这是布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000" >
<android.support.wearable.view.WearableListView
android:id="@+id/wearable_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="35dp"
android:clipToPadding="false" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="49dp"
android:id="@+id/header"
android:background="#1E1E20">
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:id="@+id/header_text"
android:layout_marginTop="9dp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
就这样。在这里,您可以根据需要更改标题文本。onScroll比OnAbsolutionScrollChange工作得更好。感谢您的回答。您在OnAbsolutionScrollChangeListener中使用的变量“rk”是什么?很高兴您喜欢它!rk是我代码中的人工制品:-)它应该是向上滚动的变量头(文本编辑)。太棒了!!!让它工作!!!谢谢。尽管我必须提到,我无法让它在Java中工作(在向RelativeLayout添加header视图时获得NPE)。刚刚用xml声明了头文件,现在一切都很正常。答案被接受。基于OnAbsolutionScrollChange
@Override
public void onScroll(int i) {
header.setY(header.getY() - i);
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000" >
<android.support.wearable.view.WearableListView
android:id="@+id/wearable_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="35dp"
android:clipToPadding="false" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="49dp"
android:id="@+id/header"
android:background="#1E1E20">
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:id="@+id/header_text"
android:layout_marginTop="9dp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
final RelativeLayout header = findViewById(R.id.header);
final TextView header_text = findViewById(R.id.header_text);
header_text.setText("Configurations");
WearableListView wearableListView = findViewById(R.id.wearable_list_view);
wearableListView.addOnScrollListener(new WearableListView.OnScrollListener() {
@Override
public void onScroll(int i) {
header.setY(header.getY() - i);
}
@Override
public void onAbsoluteScrollChange(int i) {
}
@Override
public void onScrollStateChanged(int i) {}
@Override
public void onCentralPositionChanged(int i) {}
});