2012-11-28 11 views
5

मैं एक विजेट है कि एक साथ समूहीकृत कुछ नियंत्रण से बना है निर्माण करने के लिए कोशिश कर रहा हूँ में ग्रहण में प्रस्तुत करने में नाकाम रहने दृश्य।समग्र संपादन मोड

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; 
} 
} 

यहाँ है विजेट एक्सएमएल

<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" 
/> 

मेरे समस्या यह है कि यह काम करता है ठीक है जब मैं एमुलेटर (या वास्तविक डिवाइस) में इसे चलाने, लेकिन यह नियंत्रण अपने हाथ में एक ग्रे बॉक्स खींचता है और मुझे देता है यह जब मैं ग्रहण में चित्रमय संपादक पर जाने की कोशिश:

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) 

अतिरिक्त जानकारी है, मैं जाँच 0x7F030001R.layout.vario पर मैप किया गया है और इस लाइन से त्रुटि आ रही है: li.inflate(R.layout.vario, this, true);। साथ ही अगर मैं इसे li.inflate(R.layout.vario, this); करने के लिए बदल यह त्रुटि दिखा सकते हैं नहीं है, लेकिन नियंत्रण सिर्फ "रिक्त" पता चलता है, editmode में प्रस्तुत नहीं होती (अभी भी काम करता है जब वास्तव में चलाने)।

मैं वास्तव में संपादक में लेआउट कल्पना करने के लिए सक्षम होना चाहते cuz यह एक लंबे समय नाबालिग लेआउट परिवर्तन कर और उन्हें एमुलेटर में लौटा लेता होगा।

धन्यवाद

** ध्यान दें ** त्रुटि लेआउट जहां नियंत्रण रखा जाता है से आता है। अगर मैं नियंत्रण पर ग्राफिकल संपादन करता हूं तो यह वास्तव में सफलतापूर्वक प्रस्तुत करता है।

+0

मैं अपने कोड के साथ चित्रमय लेआउट में त्रुटि नहीं मिलता है। हालांकि मुझे कुछ और करने के लिए '@ drawable/circle3' को बदलना पड़ा, तो शायद समस्या है। – brillenheini

+0

क्या आपने VarioView का उपयोग करने वाले वास्तविक लेआउट को आजमाया था या आपने ग्राफिकल संपादक में vario.xml की जांच की थी। यह मेरे लिए ठीक काम करता है यदि मैं वास्तविक समग्र नियंत्रण लेआउट ग्राफिकल संपादक को देखता हूं, लेकिन अगर मैं इसे किसी अन्य लेआउट पर रखकर इसका उपयोग करने का प्रयास करता हूं तो विफल रहता है। यदि यह वास्तव में आपके लिए काम करता है, तो क्या आप कृपया एक प्रोजेक्ट फ़ाइल अपलोड कर सकते हैं ताकि मैं जांच सकूं। – macsux

उत्तर

6

ठीक है, मैं बहुत बेवकूफ लग रहा है। ग्रहण को पुनरारंभ करने के बाद सबकुछ काम करता था।

+0

वही स्थिति और एक ही समाधान। कमर 1 घंटा और आपको जवाब मिलते हैं। –

संबंधित मुद्दे