0

RelativeLayout縦横比2:1で作ってみました。レイアウトは適切にサイズ変更されておりImageView、これもRelativeLayout見栄えがします。しかしTextView、それは android:layout_centerInParent="true"表示されません。これは、親の整列、中央などの属性のいずれかを使用すると、そのビューが表示されないためです。それを修正する方法は?

MyRelativeLayout:

 @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // TODO Auto-generated method stub
    super.onMeasure(MeasureSpec.makeMeasureSpec(widthMeasureSpec, MeasureSpec.EXACTLY),
            MeasureSpec.makeMeasureSpec(widthMeasureSpec/2, MeasureSpec.EXACTLY));
}

<com.stikyapp.MyRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<ImageView android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@color/green"/>

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="textView1"/>

</com.stikyapp.MyRelativeLayout>

正方形のアスペクト比1:1を使用している場合、このコードですべて機能します

super.onMeasure(widthMeasureSpec, widthMeasureSpec);
4

1 に答える 1