0

Android ライブラリ プロジェクト内に新しいカスタム ビューを作成した後、Eclipse にそれを認識させ、[カスタム & ライブラリ ビュー] タブに追加するにはどうすればよいですか (GUI エディター内で使用できるようにします)。

4

1 に答える 1

0

ここに書かれているとおり:カスタム コンポーネント

通常の出発点は何らかの Layout であるため、 Layout を拡張するクラスを作成します。おそらく、コンボ ボックスの場合、水平方向の LinearLayout を使用することがあります。

したがって、ビューは次のようになります。

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

public class LayoutX extends LinearLayout {

    public LayoutX(Context context, AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater inf = (LayoutInflater) context.
              getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inf.inflate(pl.infografnet.GClasses.R.layout.layout_file, this, true);
    }
}

そして、layout_file.xaml は次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="button" >

    </Button>

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox" />

</LinearLayout>

私の場合はLayoutX、「カスタム & ライブラリ ビュー」タブで Eclipse にコンポーネントを表示させるだけで十分です。

于 2013-03-26T11:03:56.573 に答える