Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 screen. But I dont know how to set the height of imageview to 1/3 of the screen.

Please help me to set the imageview height to 1/3 of the screen from the layout xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" 
    android:weightSum="1">

    <ImageView
    android:id="@+id/savedImageView"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight=".33"
    android:background="@drawable/background" />

</LinearLayout>

Thanks in advance

like image 707
user2601652 Avatar asked Nov 29 '22 15:11

user2601652


1 Answers

Use this:

int displayWidth = getWindowManager().getDefaultDisplay().getHeight();

ImageView imageView = (ImageView)findViewById(R.id.image);

imageView.getLayoutParams().height = displayWidth / 3;
like image 72
g00dy Avatar answered Dec 06 '22 11:12

g00dy