私はどこかで愚かな間違いがあることを知っていますが、私はどこを見つけることができません。 私は、コンテナのコードを以下ました:Androidスタジオはカスタムコンテナ内にビューを置くことを拒否します
public class ImagesView extends LinearLayout {
public ImagesView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ImagesView(Context context) {
super(context);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
float ar=(float)896/768;
this.setMeasuredDimension(widthSize, (int) (widthSize/5*(1f/ar)));
//this.setMeasuredDimension(1280,240);
}
}
レイアウトのxml:アンドロイドスタジオで
<?xml version="1.0" encoding="utf-8"?>
<com.rhyboo.net.test.ImagesView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_light">
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:layout_weight="1" />
</com.rhyboo.net.test.ImagesView>
私は私のコンテナのサイズが正しく設定されて見ることができますが、私は、コンテナの中に何かを追加する場合、それはのように子ビューを表示しますゼロサイズ:
私は間違っていますか?
完全なレイアウトコードを入力してください。 – MemLeak
ええ、私の最初の投稿を編集しました。 – undefined