標題:
[回家作業] ImageView
[打印本頁]
作者:
周政輝
時間:
2018-10-6 12:01
標題:
[回家作業] ImageView
[attach]4923[/attach]
[attach]4924[/attach]
作者:
黃茂勛
時間:
2018-10-6 14:29
package com.example.student.myapplication;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button previous;
Button next;
ImageView imageView;
TextView textView;
int num=0;
int[] array_image = new int[6];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
declare();
}
public void declare()
{
previous = (Button) findViewById(R.id.previous);
next = (Button) findViewById(R.id.next);
imageView = (ImageView) findViewById(R.id.imageView);
textView = (TextView) findViewById(R.id.textView);
array_image[0]=R.drawable.img01;
array_image[1]=R.drawable.img02;
array_image[2]=R.drawable.img03;
array_image[3]=R.drawable.img04;
array_image[4]=R.drawable.img05;
array_image[5]=R.drawable.img06;
}
public void previous(View view) {
if(num==1)
{
num-=0;
}else
num--;
textView.setText("第"+num+"/6張");
imageView.setImageResource(array_image[num-1]);
}
public void next(View view) {
if(num==6)
{
num+=0;
}else
num++;
textView.setText("第"+num+"/6張");
imageView.setImageResource(array_image[num-1]);
}
}
複製代碼
作者:
蔡季樺
時間:
2018-10-10 17:15
package com.example.plantsai.myapplicationpic;
import android.media.Image;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button p;
Button n;
ImageView iv;
int num=1;
TextView tv;
int[] image = new int[6];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
public void init()
{
n = findViewById(R.id.button2);
p = findViewById(R.id.button);
iv = findViewById(R.id.imageView);
tv = findViewById(R.id.textView);
image[0] = R.drawable.img01;
image[1] = R.drawable.img02;
image[2] = R.drawable.img03;
image[3] = R.drawable.img04;
image[4] = R.drawable.img05;
image[5] = R.drawable.img06;
iv.setImageResource(image[0]);
rename();
n.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(num != 6)
{
num++;
rename();
iv.setImageResource(image[num-1]);
}
}
});
p.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(num != 0)
{
num--;
rename();
iv.setImageResource(image[num-1]);
}
}
});
}
public void rename()
{
tv.setText("第"+num+"/6張");
}
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<android.widget.AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="289dp"
android:layout_height="219dp"
android:layout_x="50dp"
android:layout_y="136dp"
app:srcCompat="@drawable/img01"
tools:layout_editor_absoluteX="174dp"
tools:layout_editor_absoluteY="187dp"
android:contentDescription="@string/app_name"/>
<Button
android:id="@+id/button"
android:layout_width="127dp"
android:layout_height="wrap_content"
android:layout_x="63dp"
android:layout_y="437dp"
android:text="Previous"
tools:layout_editor_absoluteX="80dp"
tools:layout_editor_absoluteY="429dp" />
<Button
android:id="@+id/button2"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:layout_x="206dp"
android:layout_y="439dp"
android:text="Next"
tools:layout_editor_absoluteX="285dp"
tools:layout_editor_absoluteY="227dp" />
<TextView
android:id="@+id/textView"
android:layout_width="174dp"
android:layout_height="44dp"
android:layout_x="0dp"
android:layout_y="0dp"
android:text="TextView"
tools:layout_editor_absoluteX="59dp"
tools:layout_editor_absoluteY="29dp" />
複製代碼
作者:
張健勳
時間:
2018-10-13 10:32
package com.smcs.yingwu.imageview;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
Button b;
Button n;
ImageView imageV;
int num=1;
int[] image = new int[6];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
public void init()
{
n = findViewById(R.id.back);
b = findViewById(R.id.next);
imageV = findViewById(R.id.imageView);
image[0] = R.drawable.img01;
image[1] = R.drawable.img02;
image[2] = R.drawable.img03;
image[3] = R.drawable.img04;
image[4] = R.drawable.img05;
image[5] = R.drawable.img06;
imageV.setImageResource(image[0]);
n.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(num != 6)
{
num++;
imageV.setImageResource(image[num-1]);
}
}
});
b.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
if(num != 0)
{
num--;
imageV.setImageResource(image[num-1]);
}
}
});
}
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<android.widget.AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="219dp"
android:layout_x="0dp"
android:layout_y="47dp"
android:contentDescription="@string/app_name"
app:srcCompat="@drawable/img01"
tools:layout_editor_absoluteX="174dp"
tools:layout_editor_absoluteY="187dp" />
<Button
android:id="@+id/back"
android:layout_width="146dp"
android:layout_height="125dp"
android:layout_x="29dp"
android:layout_y="338dp"
android:text="@string/back"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="340dp" />
<Button
android:id="@+id/next"
android:layout_width="155dp"
android:layout_height="126dp"
android:layout_x="192dp"
android:layout_y="338dp"
android:text="@string/next"
tools:layout_editor_absoluteX="252dp"
tools:layout_editor_absoluteY="412dp" />
複製代碼
作者:
陳泓瑜
時間:
2018-10-13 11:59
package com.example.red.red;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class RED extends AppCompatActivity {
int img[] = new int[6];
int i=0;
Button btn1;
Button btn2;
ImageView imageView;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_red);
img[0]=R.drawable.img01;
img[1]=R.drawable.img02;
img[2]=R.drawable.img03;
img[3]=R.drawable.img04;
img[4]=R.drawable.img05;
img[5]=R.drawable.img06;
btn1= (Button) findViewById(R.id.button);
btn2= (Button) findViewById(R.id.button2);
imageView= (ImageView) findViewById(R.id.imageView);
imageView.setImageResource(img[0]);
textView= (TextView) findViewById(R.id.textView);
textView.setText("第1/6張");
}
public void next(View view) {
if(!(i+1>=img.length))
{
imageView.setImageResource(img[++i]);
textView.setText("第"+(i+1)+"/6張");
}
}
public void last(View view) {
if(!(i-1<0))
{
imageView.setImageResource(img[--i]);
textView.setText("第" + (i+1) + "/6張");
}
}
}
複製代碼
<?xml version="1.0" encoding="utf-8"?>
<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" tools:context=".RED">
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/tb_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:titleTextColor="@android:color/white"
android:background="@color/colorPrimary">
</android.support.v7.widget.Toolbar>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:src="@drawable/img01" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="<-"
android:id="@+id/button"
android:layout_alignBottom="@+id/imageView"
android:layout_alignParentStart="true"
android:onClick="last" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="->"
android:id="@+id/button2"
android:layout_alignBottom="@+id/imageView"
android:layout_alignParentEnd="true"
android:onClick="next" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/textView"
android:textColor="@color/title"
android:layout_alignParentStart="true"
android:layout_alignBottom="@+id/tb_toolbar"
android:layout_alignParentTop="true" />
</RelativeLayout>
複製代碼
作者:
洪振庭
時間:
2018-10-13 14:14
本帖最後由 洪振庭 於 2018-10-13 14:44 編輯
package com.example.student.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
ImageView imageView;
int image[]=new int[6];
int index=0;
TextView textview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView)findViewById(R.id.imageView);
image[0]=R.drawable.img01;
image[1]=R.drawable.img02;
image[2]=R.drawable.img03;
image[3]=R.drawable.img04;
image[4]=R.drawable.img05;
image[5]=R.drawable.img06;
imageView.setImageResource(image[0]);
textview=(TextView)findViewById(R.id.textView);
}
public void previous(View view) {
if(index>0){
imageView.setImageResource(image[--index]);
textview.setText("第"+(index+1)+"頁");
}
}
public void next(View view) {
if(index<image.length){
imageView.setImageResource(image[++index]);
textview.setText("第"+(index+1)+"頁");
}
}
}
複製代碼
作者:
黃璽安
時間:
2018-10-19 18:27
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 {
Button button1, button2;
ImageView imageView;
int num = 0;
int p = 0, count;
int[] imageID = new int[6];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
}
public void init() {
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
imageView = (ImageView) findViewById(R.id.imageView);
imageID[0] = R.drawable.img01;
imageID[1] = R.drawable.img02;
imageID[2] = R.drawable.img03;
imageID[3] = R.drawable.img04;
imageID[4] = R.drawable.img05;
imageID[5] = R.drawable.img06;
}
public void Button1(View view)
{
if(num==1)
{
num+=0;
setTitle("第 " + (p + 1) + " / " + count + " 張");
}
else
num--;
setTitle("第 " + (p - 1) + " / " + count + " 張");
imageView.setImageResource(imageID[num-1]);
}
}
複製代碼
作者:
李知易
時間:
2018-10-21 19:17
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
ImageView imageView;
int image[]=new int[6];
int index=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView)findViewById(R.id.imageView);
this.setTitle("第"+(index+1)+"/6張");
image[0]=R.drawable.img01;
image[1]=R.drawable.img02;
image[2]=R.drawable.img03;
image[3]=R.drawable.img04;
image[4]=R.drawable.img05;
image[5]=R.drawable.img06;
imageView.setImageResource(image[0]);
}
public void previous(View view) {
if(index>0){
imageView.setImageResource(image[--index]);
this.setTitle("第"+(index+1)+"/6張");
}
}
public void next(View view) {
if(index<image.length - 1){
imageView.setImageResource(image[++index]);
this.setTitle("第"+(index+1)+"/6張");
}
}
}
複製代碼
作者:
李知易
時間:
2018-10-21 19:18
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="ray.ap.hw1071021.MainActivity"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
app:srcCompat="@drawable/img01"
android:id="@+id/imageView"
/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="0,1" >
<TableRow>
<Button
android:text="上一頁"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button"
android:onClick="previous" />
<Button
android:text="下一頁"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:layout_alignTop="@+id/button"
android:onClick="next" />
</TableRow>
</TableLayout>
</LinearLayout>
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2