0

いくつかのカスタム ビューを含むスクロール可能な RelativeLayout を作成しようとしています。これはシネマ ホールの平面図です。場所の x、y 座標、および幅と高さ (実際には長方形です) があります。私はそれをこのRelativeLayoutに入れました:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_height="fill_parent"
          android:layout_width="fill_parent"
          android:padding="10px">
<ScrollView
        android:layout_height="wrap_content"
        android:layout_width="fill_parent">
    <RelativeLayout android:id="@+id/scrollable_places"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content">
    </RelativeLayout>
</ScrollView>

私はそれを次のように言います:

    RelativeLayout layout = (RelativeLayout) context.findViewById(R.id.scrollable_places);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(place.getWidth(),
 place.getHeight());
    params.leftMargin = place.getX();
    params.topMargin = place.getY();
    layout.addView(new Seat(context, place), params);

座席クラスは次のようになります。

public class Seat extends View {

private Place place;
private boolean isRed = false;

public Seat(Context context, Place place) {
    super(context);
    this.place = place;
    setOnClickListener(new OnSeatClickListener());
}

@Override
protected void onDraw(Canvas canvas) {
    if (!isRed)
        canvas.drawColor(Color.GREEN);
    else
        canvas.drawColor(Color.RED);
}

    protected void setRed() {
        isRed = true;
    }

    private class OnSeatClickListener implements OnClickListener {

        @Override
        public void onClick(View view) {
            ((Seat) view).setRed();
            view.invalidate();
        }
    }
}

ビューは完全に描画されています。しかし、ビューの配列があり、そのうちのいくつかが画面の外に出ると、scrollView が機能せず、画面にスクロールがありません。このレイアウトをスクロールさせる方法はありますか?

4

2 に答える 2

4

次のxmlファイルを試してください。すべてのデバイスで動作します。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillViewport="true"
    android:padding="10px"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
    <RelativeLayout android:id="@+id/scrollable_places"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content">
    </RelativeLayout>
</ScrollView>

ありがとう。

于 2011-06-15T10:21:14.340 に答える
0

スクロール ビューandroid:layout_height="wrap_content"では、wrap_content を使用する代わりに 5 つの特定の高さのサイズを記述しました。android:layout_height="100dip"

ありがとうディーパック

于 2011-06-15T09:20:57.653 に答える