Build Robust And Good Looking User Interface Using Android ImageView Design Widget

Android ImageView example

We all know that Android platform is enriched with many best user interface design widgets. All these widgets help Android app developers to build user-friendly, robust, and a good looking Android app. And Android ImageView is one of these UI widgets. It is used to display images in your Android application.

As a matter of fact, few of our clients from Florida and Chicago also raised a question regarding their app user interface. And we assured them by discussing our Android app development plan to build android app.

The Android Imageview comes with different configuration options with different scale types. These scale types include CENTER, CENTER_CROP, FIT_CENTER, CENTER_INSIDE, FIT_END, FIT_START, FIT_XY, MATRIX.

Android ImageView Example

In today’s Android app tutorial, we’ll be creating a Android ImageView to demonstrate how to implement this widget to make android app.

Let’s Get Started

Create a new project under file menu, and modify your project details.

Create a new project in Android Studio

Select Mini SDK Version.

Select Mini SDK Version

In the next tab, add an empty activity.

add an empty activity

Lastly, customize the activity.

customize the activity

Start Code Integration

MainActivity

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ImageView imageView;
private Button btnChangeImage;
private boolean flag;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initControls();
}
private void initControls() {
imageView = (ImageView) findViewById(R.id.imageView);
btnChangeImage = (Button) findViewById(R.id.btnChangeImage);
btnChangeImage.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btnChangeImage:
if (flag) {
flag = false;
imageView.setImageResource(R.drawable.img_android_one);
} else {
flag = true;
imageView.setImageResource(R.drawable.img_android_two);
}
Toast.makeText(this, getString(R.string.image_changed), Toast.LENGTH_SHORT).show();
break;
default:
break;
}
}
}

Activity_main.xml

<?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:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context="com.imageviewdemo.MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/img_android_one" />
<Button
android:id="@+id/btnChangeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:text="@string/change_image" />
</LinearLayout>
</RelativeLayout>

Strings.xml

<resources>
<string name="change_image">Change Image</string>
<string name="image_changed">Image Changed</string>
</resources>

And we’re done!

Time to run the demo.
Android ImageView Demo

Android ImageView Tutorial

Although, this was just a simple demo app, but there is a number of things that could be done to design Android app. And if you have a startup app idea, consult with experts, or hire Android app development company to build Android app strategically.

Grab a free copy of ImageView Widget Example demo from Github.

 
 

Want to Develop Android App From Scratch? Contact Us Now

Get your free consultation now

Leave a Reply

Your email address will not be published. Required fields are marked *