I want to get my layout or view (not screen size) width an height in some android devices, so how can i do this? For example:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingRight="8dp"
android:paddingLeft="8dp"
android:id="@+id/layout_scrol_left"/>
I have this layout and i want to get layout width and height size (in dip) in runtime, how can i do that?
First of all you need to take your layout.
LinearLayout ll_left = (LinearLayout)findViewById(R.id.layout_scrol_left);
Now if ll_left is not yet drawn both ll_left.getHeight() and ll_left.getWidth() will return 0.
So you have to get them after your view is drawn:
ll_left.post(new Runnable(){
public void run(){
int height = ll_left.getHeight();
int weight = ll_left.getWidth();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With