いくつかのコントロールをグループ化して構成されるウィジェットを構築しようとしています。ここでウィジェットです:編集モードでEclipseで複合ビューをレンダリングできません
public class VarioView extends RelativeLayout {
private int value;
private ImageView m_circle;
private TextView m_varioText;
private TextView m_units;
public VarioView(Context context)
{
this(context,null);
}
public VarioView(Context context, AttributeSet attr)
{
this(context,attr, 0);
}
public VarioView(Context context, AttributeSet attr, int defStyle)
{
super(context, attr, defStyle);
//View.inflate(context, R.layout.vario, this);
LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(R.layout.vario, this, true);
m_circle = (ImageView)this.findViewById(R.id.VarioCircle);
m_varioText = (TextView)this.findViewById(R.id.VarioText);
//m_circle.setColorFilter(Color.BLUE);
}
public int getValue() {
return value;
}
public void setValue(int value) {
m_varioText.setText(Integer.valueOf(value).toString());
this.value = value;
}
}
は、ここでウィジェットXML
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/VarioCircle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:contentDescription="Vario Circle"
android:src="@drawable/circle3" />
<TextView
android:id="@+id/VarioText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="200"
android:textColor="#FF0000"
android:textSize="60sp"
android:textStyle="bold"
android:typeface="monospace" />
<TextView
android:id="@+id/VarioUnits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/VarioText"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:text="fpm"
android:textSize="20sp" />
</RelativeLayout>
</merge>
はここで円形だだ:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false"
android:color="#FF0000" >
<size
android:height="200dip"
android:width="200dip" />
<stroke
android:width="10dp"
android:color="#FF0000" />
</shape>
そして、私はちょうどこのようにそれを使用しています私のメインビューで:
<com.proflite.VarioView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
私の問題は、私はエミュレータ(または実際のデバイス)でそれを実行すると罰金が、私はEclipseでグラフィカルエディタへ行くしようとすると、それがコントロールの上に灰色のボックスを描画し、私はこれを与える:
The following classes could not be instantiated:
- com.proflite.VarioView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
android.content.res.Resources$NotFoundException: Could not resolve resource value: 0x7F030001.
at android.content.res.BridgeResources.throwException(BridgeResources.java:693)
at android.content.res.BridgeResources.getLayout(BridgeResources.java:271)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.proflite.VarioView.<init>(VarioView.java:30)
at com.proflite.VarioView.<init>(VarioView.java:23)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0( at sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:413)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:170)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:746)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:372)
エキストラ情報、私は0x7F030001
をチェックR.layout.vario
にマップされており、エラーはこの行から出ています:li.inflate(R.layout.vario, this, true);
。さらにli.inflate(R.layout.vario, this);
に変更すると、エラーは発生しませんが、コントロールは単に「空白」と表示され、editmodeでレンダリングされません(実際に実行されても動作します)。
私は本当にエディタのレイアウトを視覚化できるようにするために、マイナーなレイアウト変更を行い、エミュレータでそれらを再実行するのに時間がかかります。
おかげ
**注**エラーがコントロールが配置されたレイアウトから来ています。コントロール自体をグラフィカルに編集すると、実際には正常にレンダリングされます。
私はあなたのコードでグラフィカルレイアウトでエラーが発生しません。 @ drawable/circle3を別のものに変更しなければならなかったのですが、おそらく問題があります。 – brillenheini
VarioViewを使用する実際のレイアウトを試しましたか、グラフィカルエディタでvario.xmlを確認しましたか?実際のコンポジットコントロールレイアウトのグラフィックエディタを表示するとうまく動作しますが、別のレイアウトに配置して使用すると失敗します。配置されて実際にあなたのために働く場合は、私は確認することができますどこかにプロジェクトファイルをアップロードしてください。 – macsux