これは私のコードですFrameLayout
:
<FrameLayout
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageView
android:id="@+id/frameView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/image1"
/>
</FrameLayout>
ImageView はよく表示されます。
これで、FrameLayout から拡張されたカスタム レイアウト (MyFrameLayout など) が作成されました。
MyFrameLayout では、レイアウトの高さを常に幅の半分にしたいので、私のコードは次のとおりです。
public class MyFrameLayout extends FrameLayout {
// 3 constructors just call super
@Override
protected void onMeasure(int widthMeasureSpec,
int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = (int) (width * 0.5);
setMeasuredDimension(width, height);
}
}
次に、xml で使用します。
<com.test.MyFrameLayout
android:layout_width="fill_parent" android:layout_height="wrap_content">
<ImageView
android:id="@+id/frameView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/image1"
/>
</com.test.MyFrameLayout>
しかし今、内側の ImageView は消えました。
私は正しく実装していonMeasure
ないと思います。onLayout
子ビューのサイズも変更する必要があると思います。しかし、私は今何をすべきかわかりません。
アップデート
TheDimasigのコメントに従って、コードをチェックして質問を更新しました。ありがとう