【发布时间】:2016-01-08 10:30:13
【问题描述】:
我有 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 视图的高度。 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
}
请告诉我如何检测 a 视图的高度?
【问题讨论】: