標題:
ImageView
[打印本頁]
作者:
tonyh
時間:
2017-6-24 17:14
標題:
ImageView
本帖最後由 tonyh 於 2017-6-24 17:59 編輯
[attach]2274[/attach] [attach]2275[/attach]
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private int imgId[]={R.drawable.img01,R.drawable.img02,R.drawable.img03,R.drawable.img04,R.drawable.img05,R.drawable.img06};
private Button btn1, btn2;
private ImageView iv;
private int p=0, count=imgId.length;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("第 "+(p+1)+" / "+count+" 張");
btn1= (Button) findViewById(R.id.button1);
btn2= (Button) findViewById(R.id.button2);
iv= (ImageView) findViewById(R.id.imageView);
btn1.setOnClickListener(myListener);
btn2.setOnClickListener(myListener);
}
private View.OnClickListener myListener=new View.OnClickListener() {
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.button1:
p--;
if(p<0)
p=count-1;
iv.setImageResource(imgId[p]);
setTitle("第 "+(p+1)+" / "+count+" 張");
break;
case R.id.button2:
p++;
if(p==count)
p=0;
iv.setImageResource(imgId[p]);
setTitle("第 "+(p+1)+" / "+count+" 張");
break;
}
}
};
}
複製代碼
作者:
李允軒
時間:
2017-7-1 12:29
package com.example.jerry.myapplication;
import android.media.Image;
import android.media.ImageReader;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private int imgId[]={R.drawable.img01,R.drawable.img02,R.drawable.img03,R.drawable.img04,R.drawable.img05,R.drawable.img06};
private Button bt1,bt2;
private ImageView imv;
private int p=0, count=imgId.length;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("第 " + (p + 1) + " / " + count + " 張");
bt1= (Button) findViewById(R.id.button1);
bt2= (Button) findViewById(R.id.button2);
imv= (ImageView) findViewById(R.id.imageView);
bt1.setOnClickListener(myLisiner);
bt2.setOnClickListener(myLisiner);
}
private View.OnClickListener myLisiner=new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
p--;
if (p<0)
p=count--;
imv.setImageResource(imgId[p]);
setTitle("第 " + (p + 1) + " / " + count + " 張");
break;
case R.id.button2:
p++;
if (p==count)
p=0;
imv.setImageResource(imgId[p]);
setTitle("第 " + (p + 1) + " / " + count + " 張");
break;
}
}
};
}
複製代碼
作者:
林宇翔
時間:
2017-7-1 17:01
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private int imgId[]=
{R.drawable.img01,R.drawable.img02,R.drawable.img03,R.drawable.img04,R.drawable.img05,R.drawable.img06};
private Button btn1,btn2;
private ImageView iv;
private int p=0, count=imgId.length;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("第 " + (p + 1) + " / " + count + " 張");
btn1= (Button) findViewById(R.id.button1);
btn2= (Button) findViewById(R.id.button2);
}
private View.OnClickListener myListener=new View.OnClickListener() {
@Override
public void onClick(View v) {
switch(v.getId())
{
case R.id.button1:
p--;
if(p<0)
p=count-1;
iv.setImageResource(imgId[p]);
setTitle("第 "+(p+1)+" / "+count+" 張");
break;
case R.id.button2:
p++;
if(p==count)
p=0;
iv.setImageResource(imgId[p]);
setTitle("第 "+(p+1)+" / "+count+" 張");
break;
}
}
};
}
複製代碼
作者:
張彥承
時間:
2017-7-6 18:31
package com.example.jerry.myapplication;
import android.media.Image;
import android.media.ImageReader;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
private int imgId[]={R.drawable.img01,R.drawable.img02,R.drawable.img03,R.drawable.img04,R.drawable.img05,R.drawable.img06};
private Button bt1,bt2;
private ImageView imv;
private int p=0, count=imgId.length;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("第 " + (p + 1) + " / " + count + " 張");
bt1= (Button) findViewById(R.id.button1);
bt2= (Button) findViewById(R.id.button2);
imv= (ImageView) findViewById(R.id.imageView);
bt1.setOnClickListener(myLisiner);
bt2.setOnClickListener(myLisiner);
}
private View.OnClickListener myLisiner=new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button1:
p--;
if (p<0)
p=count--;
imv.setImageResource(imgId[p]);
setTitle("第 " + (p + 1) + " / " + count + " 張");
break;
case R.id.button2:
p++;
if (p==count)
p=0;
imv.setImageResource(imgId[p]);
setTitle("第 " + (p + 1) + " / " + count + " 張");
break;
}
}
};
}
複製代碼
作者:
劉得恩
時間:
2018-5-24 12:26
package com.example.adm.imageview;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private int imgId[]={R.drawable.img01,R.drawable.img02,R.drawable.img03,R.drawable.img04,R.drawable.img05,R.drawable.img06};
private Button btn1, btn2;
private ImageView iv;
private int p=0, count=imgId.length;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("第" + (p + 1) + "/" + count + " 張");
btn1=(Button)findViewById(R.id.btn1);
btn2=(Button)findViewById(R.id.btn2);
iv=(ImageView)findViewById(R.id.imageView);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
p--;
if(p<0)
p=count-1;
iv.setImageResource(imgId[p]);
setTitle("第" + (p + 1) + "/" + count + " 張");
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
p++;
if(p==count)
p=0;
iv.setImageResource(imgId[p]);
setTitle("第" + (p + 1) + "/" + count + " 張");
}
});
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2