1

コンテキスト: J2ME、LWUIT、ノキア S40

私はここ数日、これに苦労してきました。ContainerList を使用する場合、ContainerList や要素のパディング、マージン、ボーダーをどれだけ変更しても、各要素の周囲には常に 2px のマージンがあります。私が話していることを示すために、このサンプル midlet をまとめました。

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

import com.sun.lwuit.Command;
import com.sun.lwuit.Component;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.list.CellRenderer;
import com.sun.lwuit.list.ContainerList;
import com.sun.lwuit.list.DefaultListModel;

public class Test extends MIDlet {

public Test() {

}

protected void startApp() throws MIDletStateChangeException {
    Display.init(this);

    Form form = new Form("ContainerList margin test");

    DefaultListModel model = new DefaultListModel();
    for(int i=0; i<100; i++){
        model.addItem(new String("Element " + i));
    }

    ContainerList list = new ContainerList(new BoxLayout(BoxLayout.Y_AXIS), model);
    list.getStyle().setBgColor(0x00FF00);
    list.getStyle().setBgTransparency(255);
    list.getStyle().setPadding(0,0,0,0);
    list.getStyle().setMargin(0,0,0,0);
    list.getStyle().setBorder(null);

    list.setRenderer(new CellRenderer(){

        public Component getCellRendererComponent(Component plist,
                Object pmodel, Object pvalue, int index, boolean selected) {

            Label l = new Label((String) pvalue);
            l.getStyle().setBgColor(0xff0000);
            l.getStyle().setBgTransparency(255);
            l.getStyle().setPadding(0,0,0,0);
            l.getStyle().setMargin(0,0,0,0);
            l.getStyle().setBorder(null);
            l.getPressedStyle().setBgColor(0x000000);
            l.getPressedStyle().setBgTransparency(255);
            l.getSelectedStyle().setBgColor(0xFFFFFF);
            l.getSelectedStyle().setBgTransparency(255);

            return l;
        }

        public Component getFocusComponent(Component arg0) {
            Label l2 = new Label();
            l2.getStyle().setBgColor(0xFF00FF);
            l2.getStyle().setBgTransparency(255);
            return l2;
        }

    });

    form.addComponent(list);

    Command exitCommand = new Command("Exit") {

        public void actionPerformed(ActionEvent e) {
            notifyDestroyed();
        }
    };
    form.addCommand(exitCommand);

    form.show();
}

protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

}

protected void pauseApp() {

}

}

問題#1:

ご覧のとおり、リスト自体とすべての要素の両方でマージン、パディング、ボーダーを削除します。ただし、nokia s40 エミュレーターでは、常にすべての要素の周囲に 2px のマージンが表示されます。

このために変更する必要がある他のスタイルを忘れましたか? getSideGap と getBottomGap を確認しましたが、問題は発生していません。

問題#2:

印刷時に要素を強調するにはどうすればよいですか? 押されたスタイルまたは選択されたスタイルを設定しても違いはなく、フォーカスコンポーネントを返すことでも違いはありませんでした。タッチに関するフィードバックがあればうれしいです (私はタッチ デバイスのみをターゲットにしているので、フォーカスは問題ではありません)。

4

1 に答える 1