1.activity_stack_view.xhtml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".StackViewActivity" >    <StackView        android:id="@+id/stackView1"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <LinearLayout        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:loopViews="true"        android:layout_toRightOf="@+id/stackView1"        android:orientation="vertical" >        <Button            android:id="@+id/previousButton"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="前一张" />        <Button            android:id="@+id/nextButton"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="后一张" />    </LinearLayout></RelativeLayout>

2.StackViewActivity.java

package com.example.webview;import android.os.Bundle;import android.app.Activity;import android.graphics.Color;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.StackView;public class StackViewActivity extends Activity {    private int[] mColors = { Color.BLUE, Color.CYAN, Color.GRAY, Color.GREEN,            Color.RED };    private StackView stackView;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_stack_view);        stackView = (StackView) findViewById(R.id.stackView1);        ColorAdapter colorAdapter = new ColorAdapter(this, mColors);        stackView.setAdapter(colorAdapter);                                                      final Button previousButon = (Button) findViewById(R.id.previousButton);        previousButon.setOnClickListener(new OnClickListener() {            public void onClick(View view) {                stackView.showPrevious();            }        });        final Button nextButton = (Button) findViewById(R.id.nextButton);        nextButton.setOnClickListener(new OnClickListener() {            public void onClick(View view) {                stackView.showNext();            }        });    }    @Override    public boolean onCreateOptionsMenu(Menu menu) {        // Inflate the menu; this adds items to the action bar if it is present.        getMenuInflater().inflate(R.menu.stack_view, menu);        return true;    }}

3.ColorAdapter.java

package com.example.webview;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.LinearLayout;public class ColorAdapter extends BaseAdapter {                    private Context mContext;                    private int [] mColors;                    public ColorAdapter(Context context, int [] colors) {        mContext = context;        mColors = colors;    }                    public int getCount() {        return mColors == null ? 0 : mColors.length;    }                public Object getItem(int position) {        return mColors == null ? null : mColors[position];    }                public long getItemId(int position) {        return position;    }                public View getView(int position, View cacheView, ViewGroup parent) {        LinearLayout.LayoutParams colorLayoutParams = new LinearLayout.LayoutParams(100, 100);                            LinearLayout colorLayout = new LinearLayout(mContext);        colorLayout.setBackgroundColor(mColors[position]);        colorLayout.setLayoutParams(colorLayoutParams);                            return colorLayout;    }            }

5.AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.webview"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="14"        android:targetSdkVersion="17" />    <uses-permission android:name="android.permission.INTERNET" />    <uses-permission android:name="android.permission.READ_CONTACTS" />    <application        android:allowBackup="false"        android:icon="@drawable/icon"        android:label="@string/app_name" ><activity            android:name="com.example.webview.StackViewActivity"            android:label="@string/title_activity_stack_view" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>


更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)NavigationDrawer(侧滑导航
  2. Android(安卓)ReplacementSpan 文字对齐
  3. Android之Zygote启动详解
  4. Android(安卓)-对图片Drawable进行变色
  5. Android(安卓)Gradle plugin升级 3.0.1
  6. android studio 3.0.1依赖butterknife报
  7. NDK Mediacodec
  8. Android(安卓)popupwindow 示例程序一
  9. android简单的多人聊天程序--借助Bmob后
  10. Android(安卓)使用Intent和Bundle传递数