話不多說,直接上碼:xml文件,簡單的線性布局
創(chuàng)新互聯(lián)公司2013年至今,是專業(yè)互聯(lián)網(wǎng)技術服務公司,擁有項目成都網(wǎng)站設計、成都網(wǎng)站建設網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元簡陽做網(wǎng)站,已為上家服務,為簡陽各地企業(yè)和個人服務,聯(lián)系電話:18980820575
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:text="下一張"
android:layout_gravity="right" />
<ImageView
android:id="@+id/p_w_picpath2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/cat"
android:scaleType="fitCenter"
/>
</LinearLayout>
效果圖
package com.example.administrator.myapplication;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
/**
* Created by Administrator on 2015/6/6.
*/
public class Textp_w_picpathActivity extends Activity{
//定義一個訪問照片的數(shù)組
int[] p_w_picpaths=new int[]{
R.drawable.cat,
R.drawable.dog,
R.drawable.happen,
R.drawable.hashiqi,
R.drawable.what,
R.drawable.name,
};
//定義默認顯示的照片
int currentImg=2;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//隱藏TITLE
setContentView(R.layout.p_w_picpathview);
final ImageView p_w_picpath2=(ImageView)findViewById(R.id.p_w_picpath2);
final Button next=(Button)findViewById(R.id.button3);
//定義查看下一張圖片的監(jiān)聽器
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//控制Image View顯示下一張照片
p_w_picpath2.setImageResource(
p_w_picpaths[++currentImg % p_w_picpaths.length]
);
}
});
}}
當前文章:實現(xiàn)Button控制ImageView顯示下一張照片
網(wǎng)址分享:http://chinadenli.net/article0/jsioio.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、虛擬主機、網(wǎng)站導航、外貿(mào)網(wǎng)站建設、網(wǎng)站設計、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)