Example with ImageView.setImageResource
File conntent_main.xml:
<ImageView android:id="@+id/imgview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="70dp" />
File MainActivity.java
After: public class MainActivity extends AppCompatActivity {
add
public ImageView imgview;
And in method onCreate add
imgview = (ImageView) findViewById(R.id.imgview); if (!imgview.isInEditMode()) { imgview.setImageResource(R.drawable.logo); }
We will get the result:
Example with ImageView.setScaleType
File content_main.xml
<ImageView android:id="@+id/imgview" android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/logo" android:layout_marginTop="70dp" />
File MainActivity.java
And in method onCreate add
imgview = (ImageView) findViewById(R.id.imgview); if (!imgview.isInEditMode()) { imgview.setScaleType(ImageView.ScaleType.FIT_START); }