Set The Height Of Imageview According To Screen From The Layout
I am making the layout and using the layout_weight and weight_sum. I am making the orientation of linear layout to horizontal so i am able to set the width of imageview 1/3 of the
Solution 1:
Use this:
intdisplayWidth= getWindowManager().getDefaultDisplay().getHeight();
ImageViewimageView= (ImageView)findViewById(R.id.image);
imageView.getLayoutParams().height = displayWidth / 3;
Solution 2:
if you put an outer horizontal linearlayout like this, you will both have 1/3 screen width and 1/3 screen height for your imageview. The inner linearlayout is vertical so you can just use that if you just need 1/3 screen height
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/out"android:weightSum="3"android:layout_width="match_parent"android:orientation="horizontal"android:layout_height="match_parent" ><LinearLayoutandroid:layout_width="0px"android:layout_height="match_parent"android:layout_weight="1"android:orientation="vertical"android:weightSum="3" ><ImageViewandroid:id="@+id/savedImageView"android:layout_width="fill_parent"android:layout_height="0px"android:layout_weight="1"android:background="@drawable/yourdrawablename" /></LinearLayout></LinearLayout>
Solution 3:
Do u need some thing like this or please elaborate u r problem more so that i can help u
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"android:weightSum="1"><ImageViewandroid:id="@+id/savedImageView"android:layout_width="0dip"android:layout_height="414dp"android:layout_weight="0.52"android:background="@drawable/ic_launcher" /></LinearLayout>
Post a Comment for "Set The Height Of Imageview According To Screen From The Layout"