Android ImageView的宽度在恢复时仍为0?
我有一个TextView和ImageView,它应该延伸到可用的宽度:Android ImageView的宽度在恢复时仍为0?,android,android-imageview,Android,Android Imageview,我有一个TextView和ImageView,它应该延伸到可用的宽度: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="TextView" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_launcher" />
</LinearLayout>
我尝试使用OnGlobalLayoutListener
,但这不起作用,因为我有几个此片段的实例
有什么建议吗
解决方案:
最后,我通过以下方式解决了问题:
text.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
发布绘制布局的代码我对你的问题没有答案,但不要这样做:“if(name==”){@pskink我也不喜欢,但它有什么害处吗?还有什么选择……将
null
设置为默认未知值?
text.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);