Android Image View
![]() |
Android Development |
Android Imageview :-
⇛ layout > .xml file :
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".First"
android:orientation="vertical"
android:gravity="center"
android:padding="5dp">
<ImageView
android:id="@+id/Idimageview1"
android:layout_width="300dp"
android:layout_height="400dp"
android:src="@drawable/dbk" />
<TextView
android:id="@+id/Idtextview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="#05fdbf"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".First"
android:orientation="vertical"
android:gravity="center"
android:padding="5dp">
<ImageView
android:id="@+id/Idimageview1"
android:layout_width="300dp"
android:layout_height="400dp"
android:src="@drawable/dbk" />
<TextView
android:id="@+id/Idtextview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:textColor="#05fdbf"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
⇛ drawable > .png/ .jpg file :
![]() |
you image .png / .jpg file |
⇛ java file :
package com.example.dell.imageview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
public class First extends AppCompatActivity {
private ImageView img1 ;
private TextView txt1;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
img1 = (ImageView) findViewById(R.id.Idimageview1);
txt1 = (TextView) findViewById(R.id.Idtextview1);
/*When click on ImageView then set the text and show TextView*/ img1.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
txt1.setText("Dhiraj says Hii...!");
}
});
}
}
No comments