எவ்வாறு Android Studio யில் ஒரு Button னை அழுத்தும் போது படம் ஒன்றை தோன்ற வைப்பது?


1.முதலில் நீங்கள் Show பண்ணவிரும்பிய படத்தை Copy செய்து app > res> drawable     path இல் படத்தை paste செய்யுங்கள்.

2. app > res > layout> activity_main க்கு சென்று கீழே தரப்பட்டுள்ள Code ஐ உள்ளீடு          செய்யுங்கள்.

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout 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="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">


<ImageView
android:id="@+id/img"
android:layout_width="match_parent"
android:layout_height="276dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/img_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/img"
android:layout_alignParentBottom="true"
android:text="Show Image"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/img"
app:layout_constraintVertical_bias="0.176" />
</androidx.constraintlayout.widget.ConstraintLayout>

3.app > java > your(package) > MainActivityக்கு சென்று கீழே தரப்பட்டுள்ள Code ஐ உள்ளீடு செய்யுங்கள்.

(Note R.drawable.show_image என்ற இடத்தில் நீங்கள் past செய்த படத்தின் பெயரை உள்ளீடு செய்யுங்கள்)
package mit.solution.apps;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

ImageView imageView;
Button showImgbtn;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = findViewById(R.id.img);
showImgbtn = findViewById(R.id.img_btn);

showImgbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageView.setImageResource(R.drawable.show_image);
}
});

}
}






கருத்துரையிடுக

Post a Comment (0)

புதியது பழையவை