編輯:關於Android編程
WearableListView是適用於android小型設備如智能手表顯示列表的組件,可以村子滾動,非常方便的在只能手表上顯示列表控件,每次顯示三個列表在屏幕中間位置。
它繼承RecyclerView,實現了OnScrollListener接口。
public class WearableListView extends android.support.v7.widget.RecyclerView implements android.support.v7.widget.RecyclerView.OnScrollListener { …. …. }下面是使用的例子
package com.technotalkative.wearablelistviewdemo; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.support.wearable.view.WatchViewStub; import android.support.wearable.view.WearableListView; import android.view.LayoutInflater; import android.view.ViewGroup; import android.widget.TextView; import java.util.ArrayList; public class SimpleListActivity extends Activity implements WearableListView.ClickListener{ private WearableListView mListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { mListView = (WearableListView) stub.findViewById(R.id.listView1); mListView.setAdapter(new MyAdapter(SimpleListActivity.this)); mListView.setClickListener(SimpleListActivity.this); } }); } private static ArrayListlistItems; static { listItems = new ArrayList (); listItems.add("Monday"); listItems.add("Tuesday"); listItems.add("Wednesday"); listItems.add("Thursday"); listItems.add("Friday"); listItems.add("Saturday"); } @Override public void onClick(WearableListView.ViewHolder viewHolder) { } @Override public void onTopEmptyRegionClick() { } private class MyAdapter extends WearableListView.Adapter { private final LayoutInflater mInflater; private MyAdapter(Context context) { mInflater = LayoutInflater.from(context); } @Override public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new WearableListView.ViewHolder( mInflater.inflate(R.layout.row_simple_item_layout, null)); } @Override public void onBindViewHolder(WearableListView.ViewHolder holder, int position) { TextView view = (TextView) holder.itemView.findViewById(R.id.textView); view.setText(listItems.get(position).toString()); holder.itemView.setTag(position); } @Override public int getItemCount() { return listItems.size(); } } }
private final class MyItemView extends FrameLayout implements WearableListView.Item { final CircledImageView imgView; final TextView txtView; private float mScale; private final int mFadedCircleColor; private final int mChosenCircleColor; public MyItemView(Context context) { super(context); View.inflate(context, R.layout.row_advanced_item_layout, this); imgView = (CircledImageView) findViewById(R.id.image); txtView = (TextView) findViewById(R.id.text); mFadedCircleColor = getResources().getColor(android.R.color.darker_gray); mChosenCircleColor = getResources().getColor(android.R.color.holo_blue_dark); } @Override public float getProximityMinValue() { return mDefaultCircleRadius; } @Override public float getProximityMaxValue() { return mSelectedCircleRadius; } @Override public float getCurrentProximityValue() { return mScale; } @Override public void setScalingAnimatorValue(float value) { mScale = value; imgView.setCircleRadius(mScale); imgView.setCircleRadiusPressed(mScale); } @Override public void onScaleUpStart() { imgView.setAlpha(1f); txtView.setAlpha(1f); imgView.setCircleColor(mChosenCircleColor); } @Override public void onScaleDownStart() { imgView.setAlpha(0.5f); txtView.setAlpha(0.5f); imgView.setCircleColor(mFadedCircleColor); } }
main.xml代碼如下: .java代碼如下: package org.lxh.demo; import androi
Android中啟動一個Activity如果點擊Home鍵該Activity是不會被銷毀的,但是當進行某些操作時某些數據就會丟失,如下:Java class:packag
有話微笑說是什麼?聽名字就覺得很新奇,這款app之所以這麼火爆,就是因為非常可靠,而且打電話非常便宜,有了它,能夠幫你每個月節省很多話費。有話微笑說怎麼打電
NumberPickerViewanother NumberPicker with more flexible attributes on Android platfor