すでに既存のコントロールで好きな場所に追加できる再利用可能なコントロールを作成しようとしているので、属性は必要ありません。追加するものは必要ありません。
「カスタムビュー」をレイアウトにドラッグするときに、視覚エディターを表示するだけです。
簡単なことです view_textseek.xml 3つの異なる場所で使用した場合に備えて、「テキストとシークバー」が必要なときにレイアウトを再作成したくないレイアウトの例として(たとえば、後でカラーピッカー)。または、「TextView」と「SeekBar」の両方を備えた単なるコントロール
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/view_textseek_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:paddingLeft="15dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="@string/view_textseek_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RelativeLayout
android:id="@+id/view_textseek_container_seekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/view_textseek_text"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:paddingBottom="5dp" >
<SeekBar
android:id="@+id/view_textseek_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:max="255"
android:progress="0" />
</RelativeLayout>
</RelativeLayout>
そして、これは基本的に私のクラスです:
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
public class TextSeekView extends RelativeLayout
{
public TextSeekView(Context context) { super(context); init(context); }
public TextSeekView(Context context, AttributeSet attrs) { super(context, attrs); init(context); }
public TextSeekView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(context); }
protected void init(Context context)
{
if (!isInEditMode())
{
LayoutInflater layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.view_textseek, this, true);
}
}
}
ご覧のとおり、既存の複数のコントロールを「収集」し、これらを処理するために「ビュー」または「コントロール」を1つ持っています。編集者には表示されません。
または、これは、「カスタム」ビューを正しくロードするために環境を再起動する必要がある古いタイプのばかげたバグのためですか?
そして、他のビューに特別な属性は必要ありません。まったく何もありません。このレイアウトや、他のレイアウトを追加するときに何度も何度も見せたいと思っています。
C#と同様に、3つのテキストボックスをコントロールに追加するだけで、毎回3つのテキストボックスを使用します。次に、3つのテキストボックスが必要なときはいつでもフォームにそのコントロールをドラッグします - それ以上はありません!