gpt4 book ai didi

android - 复合 View 无法在编辑模式下在 Eclipse 中呈现

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:33:10 24 4
gpt4 key购买 nike

我正在尝试构建一个由几个组合在一起的控件组成的小部件。这是小部件:

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); 它不会给出错误,但控件仅显示“空白”,不会在编辑模式下呈现(实际运行时仍然有效)。

我真的很希望能够在编辑器中可视化布局,因为对布局进行细微更改并在模拟器中重新运行它们需要很长时间。

谢谢

** 注意 ** 错误来自放置控件的布局。如果我对控件本身进行图形编辑,它实际上会成功呈现。

最佳答案

好吧,我觉得很愚蠢。重新启动 Eclipse 后一切正常。

关于android - 复合 View 无法在编辑模式下在 Eclipse 中呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13612559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com