如何在WearablListView设置布局topEmptyRegion? [英] How to set layout for topEmptyRegion in WearablListView?
问题描述
断开连接区域是顶级的空区域时,该列表视图滚动那向上滚动。如何设置的布局是什么?谢谢你。
The "Disconnected" region is the top empty region thats scrolls up when this listview is scrolled. How do I set layout for that? Thanks.
推荐答案
使用它是这样实现的hierarchyviewer在你的例子展望:
Looking at your example using the hierarchyviewer it is implemented like this:
一个RelativeLayout的持有WearableListView
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>
在你的onCreate()活动的方法添加标题:
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) {}
});
要概括起来讲,你有WearableListView上述视图和滚动ListView控件时,您只需滚动标题淡出人们的视线。
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.
希望这有助于。
修改2014年9月17日
如果您想报头中从顶部滚动(如谷歌的例子),添加一个文件RES /动画/ slidein_top.xml:
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>
这code至您的活动:
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);
}
}
这应该做的伎俩。
这篇关于如何在WearablListView设置布局topEmptyRegion?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!