Skip to content Skip to sidebar Skip to footer

Add Image To My Layout With Size Proportional To Dimension Of Screen Android

In my application i have an image that should have 25% width and height of screen. I hope this is clear. This is what i'm already tried but doesn't work. Thank you.

Solution 1:

Just use thiswithLinearLayout

   <LinearLayoutxmlns: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"android:orientation="vertical"android:weightSum="100">




    <ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_weight="25"android:background="@drawable/ic_launcher"/>
</LinearLayout>

Solution 2:

As I understood, your need is to relate your image view dimension with the device screen.

Here is it.

@OverrideprotectedvoidonResume() {
    super.onResume();
      int w= getWindowManager().getDefaultDisplay().getWidth(); 
   Log.d("Nzm", ""+w);
    ImageView img=(ImageView)findViewById(R.id.imageview1);
   img.setWidth((int)(w/4));// to set 25%
}

Also, make sure inside layout, the parent width is fillparent, and set the id for imageview.

Solution 3:

try this

android:layout_width="wrap_content"

Post a Comment for "Add Image To My Layout With Size Proportional To Dimension Of Screen Android"