Reputation: 6912
My layout as below:
<LinearLayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
My code as below:
TextView title = (TextView)findViewById(R.id.title);
title.setText("ABCDE...");
title.setTextSize(20);
TextView info = (TextView)findViewById(R.id.info);
info.setText("abcde...");
info.setTextSize(16);
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
I want to get the height of TextView title and info, or the height of layout. How to do it?
Upvotes: 0
Views: 5052
Reputation: 40406
@Ovveride onWindowFocusChanged method in your activity
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
int x = title.getHeight();
int y = info.getHeight();
int z = layout.getHeight();
}
Upvotes: 1
Reputation: 13552
use the getHeight() function of the View. so in ure case, info.getHeight(), layout.getHeight() etc.
Upvotes: 0
Reputation:
You can try getLineHeight() method. Such as:
title.getLineHeight();
info.getLineHeight();
Upvotes: 4