У меня 2 макета:Как определить высоту представления?
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns: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">
<RelativeLayout
android:id="@+id/addhere"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</ScrollView>
a.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_height="200dp"
android:layout_width="match_parent"/>
</LinearLayout>
и я хочу, чтобы раздуть макет a.xml и добавить его в группу просмотра с id addhere, а затем определить высоту представления. a.getHeight()
дает мне 0.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View a = getLayoutInflater().inflate(R.layout.a,null);
ViewGroup b = (ViewGroup)findViewById(R.id.addhere);
b.addView(a);
Log.d("states", a.getHeight() + ""); // show me 0
}
Пожалуйста, скажите мне, как я могу обнаружить высоту Высказаться?