0

カスタム ビューを作成し、これを LinearLayout に配置しました。

問題は、レイアウトの高さを完全に埋めることができないことです。カスタム ビューのサイズは常に正方形で、幅 = 高さです。

これが私のレイアウトです:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" 
    android:layout_weight="0">

    <it.inav.graphics.MapView
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"/>

   </LinearLayout>

それが機能しているように見える唯一の方法は、RelativeLayout を使用し、両方を使用してビューを「強化」することです

        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true" 

それでも、サイズの高さを取得しようとすると、以前と同じ長さが返されます。

4

1 に答える 1

0

問題はビューの定義にあり、XML にはありませんでした。

このコードをコピーして貼り付けました:

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int measuredWidth = measure(widthMeasureSpec);
        int measuredHeight = measure(heightMeasureSpec);
        int d = Math.min(measuredWidth, measuredHeight);
        setMeasuredDimension(d, d);
    }

そして、当然、ビューのサイズをマイナーの長さの正方形として設定します。

これは正しいコードです:

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int measuredWidth = measure(widthMeasureSpec);
        int measuredHeight = measure(heightMeasureSpec);
        setMeasuredDimension(measuredWidth, measuredHeight);
    }
于 2012-12-23T18:56:46.067 に答える